Created
February 3, 2017 20:15
-
-
Save quietsamurai98/6ed52a00c4e40adb78d21afd6ee2fb1a to your computer and use it in GitHub Desktop.
This file contains 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
--For Euler Problem 17 | |
onesNames = ["","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"] | |
teenNames = ["Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"] | |
tensNames = ["", "","Twenty","Thirty","Forty","Fifty","Sisty","Seventy","Eighty","Ninety"] | |
numberToName x = (thousands x) ++ (hundreds x) ++ (addAnd x) ++ (tens x) ++ (ones x) | |
thousands x = | |
if digit > 0 | |
then (onesNames !! digit) ++ "Thousand" | |
else "" | |
where | |
digit = mod (x `div` 1000) (10) | |
hundreds x = | |
if digit > 0 | |
then (onesNames !! digit) ++ "Hundred" | |
else "" | |
where | |
digit = mod (x `div` 100) (10) | |
addAnd x = | |
if ((div x 100) > 0) && ((mod x 100) > 0) | |
then "And" | |
else "" | |
where | |
digit = mod (x `div` 100) (10) | |
tens x = | |
if digit > 0 | |
then | |
if digit >= 2 | |
then tensNames !! digit | |
else teenNames !! (mod x 10) | |
else "" | |
where | |
digit = mod (x `div` 10) (10) | |
ones x = | |
if ((mod x 10) > 0) && ((div (mod x 100) 10) /= 1) | |
then onesNames !! (mod x 10) | |
else "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment