Jump to content

General FizzBuzz: Difference between revisions

(→‎{{header|R}}: Changed variable name, refactored if statement, and added new solution.)
Line 1,406:
<lang haskell>type Rule = (Int, String)
 
----------------- FIZZETC (USING RULE SET) ---------------
testFizz :: Int -> [String]
testFizz = fizz [(3, "Fizz"), (5, "Buzz"), (7, "Baxx")]
 
fizzfizzEtc :: [Rule] -> Int -> [String]
fizzfizzEtc rules n = foldr nextLine [] [1 .. n]
where
nextLine x a =
(if| null noise = show x : a
| otherwise = thennoise show: xa
else noise) :
a
where
noise = foldl reWrite [] rules
reWrite s (m, k) =
| 0 == rem x m = s ++<> k
(if| remotherwise x m == 0s
 
then k
 
else [])
------------------- TEST OF SAMPLE RULES -----------------
 
testFizz :: Int -> [String]
testFizz = fizzfizzEtc [(3, "Fizz"), (5, "Buzz"), (7, "Baxx")]
 
main :: IO ()
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.