A mammoth counting!

Let f ( n ) f(n) represent the total number of straight line segments in the UPPER CASE English representation of the natural number n n without adding AND and hyphen ( - ). For example, 12 can be written as TWELVE and if you carefully count all the straight-line segments in it, you get f ( n ) = 18 f(n) = 18 .

Call a number truthful if f ( n ) = n f(n) = n . What is the sum of the all truthful numbers from 1 to 9999?

Explicit Examples :

  • The letters G , I , J , Q , R , U and X contain 1, 1, 0, 1, 2, 0 and 2 straight line segments respectively.

  • Use the word ONE for denoting a single hundred or thousand and don't use the word AND anywhere.

  • Some examples of the upper representation are:
    73: SEVENTY THREE
    105: ONE HUNDRED FIVE
    1274: ONE THOUSAND TWO HUNDREDS SEVENTY FOUR
    6001: SIX THOUSANDS ONE


The answer is 45.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Snehal Shekatkar
Jul 16, 2016

The main idea is to identify few numbers whose representations cannot be created using representations of other numbers. After a little thought, it is easy to see that only such numbers below 10000 10000 are 1 1 to 20 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 , 100 , 1000 30, 40, 50, 60, 70, 80, 90, 100, 1000 . For our problem, HUNDRED and HUNDREDS are same since the last S does not contribute anything. Below is the python function which returns the upper case English representation of a given natural number. After that, finding the actual truthful numbers is quite easy. There are only two: 16 16 and 29 29 . Hence the answer is 45 \boxed{45} .

 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def number_to_name(s):    
    # Basic numbers
    basic_numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    # Basic names
    basic_names_small = [' ', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety', 'hundred']

    basic_names = [name.upper() for name in basic_names_small]

    basic_map = {}
    for n, name in zip(basic_numbers, basic_names):
        basic_map[n] = name

    current_string = s
    if s in basic_numbers:    
        return basic_map[s]   
    else:
        s1 = ''; s2 = ''; s3 = ''
        # First describe the last two digits
        last_two = str(s)[-2:]
        if last_two[0] == 0:
            s1 = basic_map[int(last_two[1])]
        elif int(last_two) in basic_numbers:
            s1 = basic_map[int(last_two)]
        else:
            s1 = basic_map[int(last_two[0]) * 10] + ' ' + basic_map[int(last_two[1])]

        # Describe the remaining number
        remaining = (str(s)[:-2])
        for i, d in enumerate(reversed(remaining)):
            if i == 0 and d != '0':
                if int(d) == 1:
                    s2 = "ONE HUNDRED"
                else:
                    s2 = basic_map[int(d)] + " HUNDREDS"
            elif i == 1 and d != '0':
                if int(d) == 1:
                    s3 = "ONE THOUSAND"
                else:
                    s3 = basic_map[int(d)] + " THOUSANDS"

        return s3 + ' ' + s2 + ' ' + s1

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...