aboutsummaryrefslogtreecommitdiff
path: root/challenge-001/alexander-pankoff/haskell/ch-2.hs
blob: 90313ac72c3412d1766d0ee658a111c9af7541fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Main where

import Data.Bifunctor (first)
import Data.Bool (bool)

main :: IO ()
main = print $ fizzBuzz 20

fizzBuzz :: Int -> [String]
fizzBuzz max =
  map
    ( \x ->
        let mfizzBuzz = fizzBuzzCycle !! pred x
         in if not $ null mfizzBuzz then mfizzBuzz else show x
    )
    [1 .. max]
  where
    fizzBuzzCycle = zipWith (++) (cycle ["", "", "Fizz"]) (cycle ["", "", "", "", "Buzz"])