yingpotter

[99p]FullWords

Aug 15th, 2011
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List
  2. import Data.Char
  3.  
  4. -----  predefined numlist
  5. numlist = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
  6.  
  7. ----- fullWords function
  8. -- Using the show function to convert an Int to a String (well, show DOES eat starting zeros)
  9. -- Also, using div/mod combination to do this will derive incorrect anwsers for inputs longer than 10 digits
  10. fullWords :: Integer -> String
  11. fullWords n
  12.           | n >= 0     = intercalate "-" (map (\x -> numlist!!x) $ map digitToInt (show n))
  13.           | n < 0      = "negative-" ++ ( intercalate "-" (map (\x -> numlist!!x) $ map digitToInt (show (-n))) )
Advertisement
Add Comment
Please, Sign In to add comment