# Number letter counts [closed]

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

Output how many letters would be used if all the numbers from 1 to 1000 (one thousand) inclusive were written out in words.

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.

You must actually calculate it - just printing the predetermined result is not allowed.

Output with any acceptable method.

• Probable duplicate of this question – Giuseppe Nov 15 '18 at 22:02
• Welcome to PPCG! To prevent hardcoding, I'd strongly recommend to either 1) take a number $1\le N \le 1000$ as input and ask the number of letters used to write $1$ to $N$ or 2) take 2 numbers $A$ and $B$ as input and ask the number of letters used to write $A$ to $B$. – Arnauld Nov 15 '18 at 22:02
• This would be better as "output how many letters are used if the numbers 1 through n were written out" to avoid any question of whether something prints a predetermined result. But I think that's a duplicate. – lirtosiast Nov 15 '18 at 22:04
• It turns out that this is a slightly edited copy of problem 17 from Project Euler. Posting such problems here is strongly discouraged, so it should probably be closed and/or deleted. – Arnauld Nov 15 '18 at 23:30
• I'm voting to close this question as off-topic because this challenge was taken from another site without any reference or authorization. – Arnauld Nov 15 '18 at 23:32

# Mathematica, 38 bytes

StringLength@StringJoin@IntegerName[Range[1000]]


@Doorknob has a leaner implementation:

Tr@StringLength@IntegerName@Range@1000


(* 20961 *)

Explanation

IntegerName[Range[10]]


(* {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"} *)

StringJoin@IntegerName[Range[10]]


(* "onetwothreefourfivesixseveneightnineten" *)

StringLength@StringJoin@IntegerName[Range[10]]


(* 39 *)

• Since StringLength threads over lists (and you can use prefix notation for all of these functions), this can be shortened to Tr@StringLength@IntegerName@Range@1000 to save 10 bytes. – Doorknob Nov 15 '18 at 23:50
• @Doorknob: Oooh... yes. Nice. Thanks. – David G. Stork Nov 15 '18 at 23:51
• The expected result is 21124. The gap is prime (21124 - 20961 = 163), so it's not $N$ times the same difference. I wonder where it comes from. – Arnauld Nov 16 '18 at 15:22
• When I delete white spaces I get 19169. – David G. Stork Nov 17 '18 at 1:03
• Are you also deleting hyphens? And are the numbers formatted the UK way? (three hundred and forty-two)? – Arnauld Nov 19 '18 at 16:06

# Common Lisp, 10498857675 74 bytes

(princ(loop for i to 999 sum(count-if'both-case-p(format nil"~R"(1+ i)))))


Try it online!