My solutions of Facebook puzzles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hoppity.hs 489B

123456789101112131415161718192021
  1. module Main () where
  2. import System.Environment
  3. import Control.Monad
  4. import Data.Maybe
  5. hoppityfy :: Int -> Maybe String
  6. hoppityfy n
  7. | n `mod` 3 == 0 && n `mod` 5 == 0 = Just "Hop"
  8. | n `mod` 3 == 0 = Just "Hoppity"
  9. | n `mod` 5 == 0 = Just "Hophop"
  10. | otherwise = Nothing
  11. main :: IO ()
  12. main = do
  13. [filename] <- getArgs
  14. content <- readFile filename
  15. let n = (read content) :: Int
  16. let hops = catMaybes . map hoppityfy $ [1 .. n]
  17. forM_ hops $ \h -> putStr . (++ "\n") $ h