Skip to content

Instantly share code, notes, and snippets.

@grejppi
Last active December 19, 2015 17:48
Show Gist options
  • Save grejppi/5993853 to your computer and use it in GitHub Desktop.
Save grejppi/5993853 to your computer and use it in GitHub Desktop.
Another "99 Bottles of Beer" in Julia
a(s)="$(uppercase(s[1]))$(s[2:])";b(n)=["one","two","three","four","five","six","seven","eight","nine","ten"][n];c(n)=["","Twen","Thir","For","Fif","Six","Seven","Eigh","Nine"][n]*((n!=1)?"ty":"");d(n)=["Eleven","Twelve","Thir","Four","Fif","Six","Seven","Eigh","Nine"][n]*((n>2)?"teen":"");e(n)=(0<n<11)?a(b(n)):((n==0)?"No more":((n>19)?"$(c(floor(n/10)))"*((%(n,10)==0)?"":"-$(b(%(n,10)))"):("$(d(n-10))")));f(n)="$(e(n)) bottle"*"s"^(n!=1?1:0)*" of beer";g(n)="\n$(f(n)) on the wall,\n$(f(n)),\n"*(n>0?"Take one down, pass it around,\n$(f(n-1)) on the wall.\n$(g(n-1))":"Go to the store and buy some more,\n$(f(99)) on the wall.\n");println(g(99))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment