Skip to content

Instantly share code, notes, and snippets.

@sadraskol
Created November 11, 2015 02:02
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 sadraskol/cccd65603ee9ddfc2438 to your computer and use it in GitHub Desktop.
Save sadraskol/cccd65603ee9ddfc2438 to your computer and use it in GitHub Desktop.
defmodule DrunkMan do
def bottle(0), do: "no more bottles"
def bottle(1), do: "1 bottle"
def bottle(n), do: to_string(n) <>" bottles"
def verse(0), do: "No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall."
def verse(n), do: "#{DrunkMan.bottle n} of beer on the wall, #{DrunkMan.bottle n} of beer.
Take one down and pass it around, #{DrunkMan.bottle(n - 1)} of beer on the wall.\n"
end
99..0
|> Enum.map(&DrunkMan.verse/1)
|> Enum.each(&IO.puts/1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment