If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?

NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.

- Code: Select all
`[ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" ]`

[ "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"] +

Constant new: UNIT

["ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" ] Constant new: TENTH

Integer method: asName

{

self 20 < ifTrue: [ UNIT at(self) return ]

self 100 < ifTrue: [ self 10 /mod TENTH at swap asName + return ]

self 1000 == ifTrue: [ "onethousand" return ]

self isMultiple(100) ifTrue: [ UNIT at(self 100 / ) "hundred" + return ]

self 100 /mod UNIT at "hundredand" + swap asName +

}

: pe017 { 0 #[ asName size + ] 1000 seqEach }