Skip to content

Instantly share code, notes, and snippets.

@Nucleareal
Created March 4, 2014 12:52
Show Gist options
  • Select an option

  • Save Nucleareal/9345929 to your computer and use it in GitHub Desktop.

Select an option

Save Nucleareal/9345929 to your computer and use it in GitHub Desktop.
99 Bottles of Beer on Haskell
import Control.Monad
show' :: Int -> String
show' x
| x == 0 = "no more bottles"
| x == 1 = "1 bottle"
| otherwise = show x ++ " bottles"
main = forM [99,98..0] (\x -> putStrLn $
if x == 0
then
"No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall."
else
show' x ++ " of beer on the wall, " ++ show' x ++ " of beer.\nTake one down and pass it around, " ++ show' (x-1) ++ "of beer on the wall.\n" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment