Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/General-FizzBuzz/Haskell/general-fizzbuzz-1.hs
Normal file
16
Task/General-FizzBuzz/Haskell/general-fizzbuzz-1.hs
Normal 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)
|
||||
23
Task/General-FizzBuzz/Haskell/general-fizzbuzz-2.hs
Normal file
23
Task/General-FizzBuzz/Haskell/general-fizzbuzz-2.hs
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue