Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Last active February 22, 2016 21:21
Show Gist options
  • Save amitaibu/d329486ed31d77ba072c to your computer and use it in GitHub Desktop.
Save amitaibu/d329486ed31d77ba072c to your computer and use it in GitHub Desktop.
module WordNumber where
import Data.List (intersperse)
digitToWord :: Int -> String
digitToWord 0 = "Zero"
digitToWord 1 = "One"
digitToWord 2 = "Two"
digitToWord 3 = "Three"
digitToWord _ = "other"
digits :: Int -> [Int]
digits 0 = []
digits n = modVal : digits divVal
where divVal = (n `div` 10)
modVal = (n `mod` 10)
wordNumber :: Int -> String
wordNumber n = concat . intersperse "-" . map digitToWord . reverse $ digits n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment