Created
November 10, 2019 23:49
-
-
Save lzakharov/309a1343e06d1797c5fece8bcd179a02 to your computer and use it in GitHub Desktop.
wordNumber returns the English word version of the Int value
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 Main where | |
| import Data.List (intercalate) | |
| digitToWord :: Int -> String | |
| digitToWord 0 = "zero" | |
| digitToWord 1 = "one" | |
| digitToWord 2 = "two" | |
| digitToWord 3 = "three" | |
| digitToWord 4 = "four" | |
| digitToWord 5 = "five" | |
| digitToWord 6 = "six" | |
| digitToWord 7 = "seven" | |
| digitToWord 8 = "eight" | |
| digitToWord 9 = "nine" | |
| digitToWord _ = "NaN" | |
| digits :: Int -> [Int] | |
| digits n = go n [] | |
| where | |
| go 0 acc = acc | |
| go x acc = go d (m:acc) | |
| where (d, m) = divMod x 10 | |
| wordNumber :: Int -> String | |
| wordNumber = intercalate "-" . map digitToWord . digits | |
| main :: IO () | |
| main = print $ wordNumber 12324546 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment