Skip to content

Instantly share code, notes, and snippets.

@chiroptical
Created October 11, 2019 21:43
Show Gist options
  • Select an option

  • Save chiroptical/c08d2affe7164aea63128b7bcba319d5 to your computer and use it in GitHub Desktop.

Select an option

Save chiroptical/c08d2affe7164aea63128b7bcba319d5 to your computer and use it in GitHub Desktop.
module Raindrops
( convert
)
where
import Data.Semigroup ( (<>) )
import Data.Maybe ( fromMaybe )
sounds :: [String]
sounds = ["Pling", "Plang", "Plong"]
convert :: Int -> String
convert n = fromMaybe (show n)
$ foldr soundIfDivisible Nothing (zip sounds [3, 5 ..])
where
soundIfDivisible (s, x) acc | n `mod` x == 0 = Just s <> acc
| otherwise = acc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment