General FizzBuzz: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) (→{{header|R}}: Changed variable name, refactored if statement, and added new solution.) |
(→{{header|Haskell}}: Tidied.) |
||
Line 1,406: | Line 1,406: | ||
<lang haskell>type Rule = (Int, String) |
<lang haskell>type Rule = (Int, String) |
||
----------------- FIZZETC (USING RULE SET) --------------- |
|||
⚫ | |||
⚫ | |||
fizzEtc :: [Rule] -> Int -> [String] |
|||
fizzEtc rules n = foldr nextLine [] [1 .. n] |
|||
where |
where |
||
nextLine x a |
nextLine x a |
||
| null noise = show x : a |
|||
| otherwise = noise : a |
|||
else noise) : |
|||
a |
|||
where |
where |
||
noise = foldl reWrite [] rules |
noise = foldl reWrite [] rules |
||
reWrite s (m, k) |
reWrite s (m, k) |
||
s |
| 0 == rem x m = s <> k |
||
| otherwise = s |
|||
then k |
|||
else []) |
|||
------------------- TEST OF SAMPLE RULES ----------------- |
|||
⚫ | |||
⚫ | |||
main :: IO () |
main :: IO () |