Skip to content

Instantly share code, notes, and snippets.

@gfixler
Created Jun 23, 2015
Embed
What would you like to do?
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