Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

99 Bottles of Elixir... #6

Open
emson opened this issue Mar 1, 2016 · 3 comments
Open

99 Bottles of Elixir... #6

emson opened this issue Mar 1, 2016 · 3 comments

Comments

@emson
Copy link
Owner

@emson emson commented Mar 1, 2016

We’re back! The slow start for 2016 has been because I’ve been completing an Elixir online video course. The course is called Elixir for Beginners http://www.elixirforbeginners.com and at the moment it’s hosted on Udemy: https://www.udemy.com/elixir-for-beginners/.

  • Write code that will output all 99 verses of the song "99 bottles of..." https://en.wikipedia.org/wiki/99_Bottles_of_Beer
  • 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.

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.

Finally...

  1. Please add your solutions as comments to this Github issue
  2. Remember to add your Twitter handle (I will link to it if you get a mention)
    Many thanks, Ben
    When the puzzle is over I'll write them up on http://elixirgolf.com and link back to your Twitter handle
@henrik
Copy link

@henrik henrik commented Mar 4, 2016

My 238 char solution is in this Gist, will keep updating it: https://gist.github.com/henrik/a21fc19cb1f8fca445e5

You can see the progress down from the initial 256 chars.

I'll assume we don't need to explicitly call the function spawn as long as a process is spawned.

Twitter: @henrik

@emson
Copy link
Owner Author

@emson emson commented Mar 4, 2016

Correct you don't need to use the spawn function as long as a process is spawned so Task can be used too.

@gvaughn
Copy link

@gvaughn gvaughn commented Mar 5, 2016

Well, I see that not only am I slow, but I'm using too many chars too: 258.
https://gist.github.com/gvaughn/fb89c65e01207f1d281d

Task is clever! I did it with raw spawn in a recursive anonymous fn. Maybe I'll get the obfuscated bonus prize :-)

Twitter: @gregvaughn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants