Skip to content

Instantly share code, notes, and snippets.

@gvaughn
Last active March 13, 2016 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvaughn/fb89c65e01207f1d281d to your computer and use it in GitHub Desktop.
Save gvaughn/fb89c65e01207f1d281d to your computer and use it in GitHub Desktop.
p=fn 0,_->;i,p->spawn fn->w=" on the wall.";b=&" #{&1} bottle#{&1==1&&""||"s"} of Elixir"
IO.puts [inspect(self),b.(i),w,b.(i),".\n",i==1&&"Go get some more,"<>b.(99)||"Take one down pass it around,"<>b.(i-1),w,10]
p.(i-1,p)end end;p.(99,p);:timer.sleep 999
@gvaughn
Copy link
Author

gvaughn commented Mar 5, 2016

Saved 3 chars at the last minute: 258

@gvaughn
Copy link
Author

gvaughn commented Mar 7, 2016

Note: the sleep call at the end feels like cheating. I had a prior solution in which the main process received the verse string from each spawned process and then printed it itself. That was well over 300 chars though.

@padde
Copy link

padde commented Mar 11, 2016

Nice solution! Here are a few ideas for improvement:

  • You can replace ".\n" with a plain newline (1 char less)
  • Maybe you did it on purpose, but the semicolons are not really necessary. You could just replace them with plain newlines as well to make it (imho) a little bit more readable. But again, maybe that's not the point ;-)
  • You can replace i==1 with i<2 or i>1 and flip the branches (two occurrences, so 2 chars less)
  • You can replace sleep 999 with sleep ?ϧ (1 char less) I learned this technique from @henrik's solution to the last elixir golf. Basically you can find the appropriate unicode character by running to_string [999] in iex.

@gvaughn
Copy link
Author

gvaughn commented Mar 11, 2016

Thanks for your reply @padde Once I saw that I was 30 chars behind @henrik I stopped trying to micro optimize

  • :-) Yes, I used semicolons instead of newlines to make it look more imposing 👿
  • That sleep ?= trick is one I hadn't thought of before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment