General FizzBuzz: Difference between revisions

Content added Content deleted
Line 1,408: Line 1,408:
----------------- FIZZETC (USING RULE SET) ---------------
----------------- FIZZETC (USING RULE SET) ---------------


fizzEtc :: [Rule] -> Int -> [String]
fizzEtc :: [(Int, String)] -> [String]
fizzEtc rules n = foldr nextLine [] [1 .. n]
fizzEtc rules = foldr nextLine [] [1 ..]
where
where
nextLine x a
nextLine x a
Line 1,422: Line 1,422:


------------------- TEST OF SAMPLE RULES -----------------
------------------- TEST OF SAMPLE RULES -----------------
fizzTest :: [String]

fizzTest = fizzEtc [(3, "Fizz"), (5, "Buzz"), (7, "Baxx")]
testFizz :: Int -> [String]
testFizz = fizzEtc [(3, "Fizz"), (5, "Buzz"), (7, "Baxx")]


main :: IO ()
main :: IO ()
main = mapM_ putStrLn (testFizz 20)</lang>
main = mapM_ putStrLn $ take 20 fizzTest
</lang>
{{Out}}
{{Out}}
<pre>1
<pre>1