summaryrefslogtreecommitdiff
path: root/Problem17.py
blob: a220e88dbfe6e677c6b745eb827dd62e489a8b4a (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def lettercountofnum(n):
    count = 0
    if len(str(n)) == 3:
        if str(n)[0] == "9":
            count = 11
        elif str(n)[0] == "8":
            count = 12
        elif str(n)[0] == "7":
            count = 12
        elif str(n)[0] == "6":
            count = 10
        elif str(n)[0] == "5":
            count = 11
        elif str(n)[0] == "4":
            count = 11
        elif str(n)[0] == "3":
            count = 12
        elif str(n)[0] == "2":
            count = 10
        else:
            count = 10
        if (str(n)[1] != "0") or (str(n)[2] != "0"): #handle "and"
            count+=3
        n = n - int(str(n)[0])*100
    if len(str(n)) == 2:
        if str(n)[0] == "9":
            count += 6
        elif str(n)[0] == "8":
            count += 6
        elif str(n)[0] == "7":
            count += 7
        elif str(n)[0] == "6":
            count += 5
        elif str(n)[0] == "5":
            count += 5
        elif str(n)[0] == "4":
            count += 5
        elif str(n)[0] == "3":
            count += 6
        elif str(n)[0] == "2":
            count += 6
        elif str(n)[0] == "1": #handle "teens" then exit
            if str(n)[1] == "9":
                count += 8
                return count
            elif str(n)[1] == "8":
                count += 8
                return count
            elif str(n)[1] == "7":
                count += 9
                return count
            elif str(n)[1] == "6":
                count += 7
                return count
            elif str(n)[1] == "5":
                count += 7
                return count
            elif str(n)[1] == "4":
                count += 8
                return count
            elif str(n)[1] == "3":
                count += 8
                return count
            elif str(n)[1] == "2":
                count += 6
                return count
            elif str(n)[1] == "1":
                count += 6
                return count
            else:
                count += 3
        n = n - int(str(n)[0])*10
    if len(str(n)) == 1:
        if str(n)[0] == "9":
            count += 4
        elif str(n)[0] == "8":
            count += 5
        elif str(n)[0] == "7":
            count += 5
        elif str(n)[0] == "6":
            count += 3
        elif str(n)[0] == "5":
            count += 4
        elif str(n)[0] == "4":
            count += 4
        elif str(n)[0] == "3":
            count += 5
        elif str(n)[0] == "2":
            count += 3
        elif str(n)[0] == "1":
            count += 3

    return count
count = 0
for x in range(1,1000):
    count += lettercountofnum(x)
print(count)