Created
May 21, 2015 10:12
-
-
Save Rembane/d34cc87ba1ad69f30310 to your computer and use it in GitHub Desktop.
Another FizzBuzz. This time with lots of recursion.
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
module Main where | |
continue :: ([a] -> [b]) -> [a] -> [b] | |
continue _ [] = [] | |
continue f (x:xs) = f (x:xs) | |
f1, f2, f3, b1, b2, b3, b4, b5 :: [Int] -> [(Bool, String)] | |
f1 (x:xs) = (False, show x):continue f2 xs | |
f2 (x:xs) = (False, show x):continue f3 xs | |
f3 (x:xs) = (True, "Fizz"):continue f1 xs | |
b1 (x:xs) = (False, show x):continue b2 xs | |
b2 (x:xs) = (False, show x):continue b3 xs | |
b3 (x:xs) = (False, show x):continue b4 xs | |
b4 (x:xs) = (False, show x):continue b5 xs | |
b5 (x:xs) = (True, "Buzz"):continue b1 xs | |
run :: [Int] -> [String] | |
run xs = zipWith go (f1 xs) (b1 xs) | |
where | |
go (False, s1) (False, _) = s1 | |
go (True, s1) (False, _) = s1 | |
go (False, _) (True, s2) = s2 | |
go (True, s1) (True, s2) = s1 ++ s2 | |
main :: IO () | |
main = mapM_ putStrLn $ run [1..100] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment