Created
October 11, 2019 21:43
-
-
Save chiroptical/c08d2affe7164aea63128b7bcba319d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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