Last active
April 6, 2021 01:27
-
-
Save ab9rf/1d1ff99b5307d7994fa3 to your computer and use it in GitHub Desktop.
Silly haskell version of that FizzBuzz problem. Written because I was bored.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- new and improved! | |
import Control.Applicative ((<|>)) | |
import Data.Maybe (catMaybes) | |
nfilter n k = cycle $ take n $ (Just k) : (repeat Nothing) | |
joinf Nothing Nothing = Nothing | |
joinf Nothing (Just a) = Just a | |
joinf (Just a) Nothing = Just a | |
joinf (Just a) (Just b) = Just $ a ++ b | |
fizzF = nfilter 3 "Fizz" | |
buzzF = nfilter 5 "Buzz" | |
fizzbuzzF = zipWith joinf fizzF buzzF | |
fizzbuzz = catMaybes $ tail $ zipWith (<|>) fizzbuzzF $ map (Just . show) [0..] | |
main = mapM_ putStrLn (take 100 fizzbuzz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment