Skip to content

Instantly share code, notes, and snippets.

@gfixler
Created June 23, 2015 16:06
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 gfixler/7c30ce9a262094d78265 to your computer and use it in GitHub Desktop.
Save gfixler/7c30ce9a262094d78265 to your computer and use it in GitHub Desktop.
99 bottles
bottles :: Int -> String
bottles x | x == 0 = "No more bottles"
| x == 1 = "1 more bottle"
| x < 13 = show x ++ " more bottles"
| otherwise = show x ++ " bottles"
verse :: Int -> String
verse x = line1 ++ "\n" ++ line2 ++ "\n\n"
where line1 = bottles x ++ obotw ++ " " ++ bottles x ++ ob
line2 = todpia ++ bottles (x-1) ++ obotw
obotw = " of beer on the wall."
ob = " of beer."
todpia = "Take one down, pass it around. "
main :: IO ()
main = mapM_ putStr $ map verse [99,98..1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment