Skip to content

Instantly share code, notes, and snippets.

@h-hirai
Created August 27, 2011 10:43
Show Gist options
  • Save h-hirai/1175236 to your computer and use it in GitHub Desktop.
Save h-hirai/1175236 to your computer and use it in GitHub Desktop.
FizzBuzz
-- http://d.hatena.ne.jp/fumokmm/20110815/1313405510
import Data.List (find)
makeAlist :: [String] -> [(Int, String)]
makeAlist [] = []
makeAlist (a:b:rest) = (read a, b):makeAlist rest
fizzbuzz :: [(Int, String)] -> [String]
fizzbuzz alist = map f [1..]
where f i = case find g alist of
Just (_, s) -> s
Nothing -> show i
where g (j, _) = i `mod` j == 0
main :: IO ()
main = mapM_ putStrLn $ take 100 $ fizzbuzz (makeAlist ["3", "Fizz",
"5", "Buzz",
"7", "Hoge"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment