Personal tools

99 questions/Solutions/95

From HaskellWiki

Jump to: navigation, search

(**) English number words

On financial documents, like cheques, numbers must sometimes be written in full words. Example: 175 must be written as one-seven-five. Write a predicate full-words/1 to print (non-negative) integer numbers in full words.

import Data.Char
import Data.List
fullWords :: Integer -> String
fullWords n = concat $ intersperse "-" [digits!!digitToInt d | d <- show n]

This solution does a simple table lookup after converting the positive integer into a string. Thus dividing into digits is much simplified.