99 Bottles of Elixir...

elixirgolf bio photo By elixirgolf Comment

Welcome Back!

We’re back! The slow start for 2016 has been because I’ve been completing an Elixir online video course Elixir for Beginners http://www.elixirforbeginners.com. Needless to say it’s taken longer than expected, and I must apologise for that.

As a thank you for all your support, ElixirGolfers can have a discount coupon of 50% off:
https://www.udemy.com/elixir-for-beginners/?couponCode=ElixirGolf50%25

I hope you enjoy it, many thanks
Ben…

Instructions

The puzzle this week is to generate verses from the old song “99 green bottles sitting on the wall…”, but with an Elixir twist!

Your task is to write code that will output all 99 verses of the song. The Elixir twist is that your program will spawn a new process for each verse, and that verse must be output to the console (the primary process). Each verse must decrease the number of bottles on the wall, and this must be sequential. Meaning that verses can’t jump around.

The verse code must be generated in it’s own process and that process PID must be returned with the verse. You can NOT just generate 99 processes, get the PIDs and interpolate them with the verse’s String. As that is cheating ;o)

For example the program will work something like this:

$> elixir bottles.exs
#PID<0.50.0> 99 bottles of Elixir on the wall, 99 bottles of Elixir.
Take one down and pass it around, 98 bottles of Elixir on the wall.

#PID<0.51.0> 98 bottles of Elixir on the wall, 98 bottles of Elixir.
Take one down and pass it around, 97 bottles of Elixir on the wall.

....

#PID<0.147.0> 2 bottles of Elixir on the wall, 2 bottles of Elixir.
Take one down and pass it around, 1 bottle of Elixir on the wall.

#PID<0.148.0> 1 bottle of Elixir on the wall, 1 bottle of Elixir.
Go code some more, 99 bottles of Elixir on the wall.

Rules

  • The code will be executed using the elixir command: elixir bottles.exs. We will manually copy the solutions into this file, so please just submit your solutions as a Github issue (please see the link below).

  • Output 99 verses of the song in the following format, with a unique PID value for each verse:

#PID<0.50.0> 99 bottles of Elixir on the wall, 99 bottles of Elixir.
Take one down and pass it around, 98 bottles of Elixir on the wall.

NB: Note that we use the plural and singular of bottle

#PID<0.148.0> 1 bottle of Elixir on the wall, 1 bottle of Elixir.
Go code some more, 99 bottles of Elixir on the wall.
  • spawn a new process for each verse, and that verse must be output to the console (the primary process).

  • Each verse will sequentially decrease the number of bottles on the wall, this sequence is important and must not jump up or down.

Submit your solution

Please submit your solution as a comment on the Github issue below, along with your Twitter handle (we will use this to link back to you if your solution is successful).

Solutions

Winner

--- your name here ---

Honourable mentions


Resources

comments powered by Disqus