Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,16 @@
fizz :: (Integral a, Show a) => a -> [(a, String)] -> String
fizz a xs
| null result = show a
| otherwise = result
where result = concatMap (fizz' a) xs
fizz' a (factor, str)
| a `mod` factor == 0 = str
| otherwise = ""
main = do
line <- getLine
let n = read line
contents <- getContents
let multiples = map (convert . words) $ lines contents
mapM_ (\ x -> putStrLn $ fizz x multiples) [1..n]
where convert [x, y] = (read x, y)

View file

@ -0,0 +1,23 @@
type Rule = (Int, String)
----------------- FIZZETC (USING RULE SET) ---------------
fizzEtc :: [(Int, String)] -> [String]
fizzEtc rules = foldr nextLine [] [1 ..]
where
nextLine x a
| null noise = show x : a
| otherwise = noise : a
where
noise = foldl reWrite [] rules
reWrite s (m, k)
| 0 == rem x m = s <> k
| otherwise = s
------------------- TEST OF SAMPLE RULES -----------------
fizzTest :: [String]
fizzTest = fizzEtc [(3, "Fizz"), (5, "Buzz"), (7, "Baxx")]
main :: IO ()
main = mapM_ putStrLn $ take 20 fizzTest