-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob17.rb
More file actions
27 lines (24 loc) · 836 Bytes
/
prob17.rb
File metadata and controls
27 lines (24 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Number letter counts
# Problem 17
#
# 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.
#
# 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.
#
# Solution: 21124
require_relative 'lib/math_english'
total_letters = 0
(1..1000).each do |num|
number_string = number_to_words(num)
total_letters += count_letters(number_string)
end
puts "The number of letters used to write out 1 to 1000 as words is: #{total_letters}"