Last active
July 21, 2016 20:18
-
-
Save aaronjensen/d273ddbee9f5fdafab28111268071a54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Bottles do | |
| def song, do: verses(99, 0) | |
| def verses(first, last) do | |
| Enum.map_join first..last, "\n", &verse/1 | |
| end | |
| 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. | |
| """ | |
| end | |
| def verse(n) do | |
| """ | |
| #{bottles(n)} of beer on the wall, #{bottles(n)} of beer. | |
| Take one down and pass it around, #{bottles(n - 1)} of beer on the wall. | |
| """ | |
| end | |
| defp bottles(0), do: "No more bottles" | |
| defp bottles(1), do: "1 bottle" | |
| defp bottles(n), do: "#{n} bottles" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment