-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0017.go
79 lines (76 loc) · 1.23 KB
/
0017.go
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
// https://projecteuler.net/problem=17
package main
func p17() int {
sum := 0
for i := 0; i < 1000; i++ {
sum += lengthNumber(i)
}
return sum + len("onethousand")
}
func lengthNumber(number int) int {
switch number {
case 0:
return 0
case 1:
return 3 //one
case 2:
return 3 //two
case 3:
return 5 //three
case 4:
return 4 //four
case 5:
return 4 //five
case 6:
return 3 //six
case 7:
return 5 //seven
case 8:
return 5 //eight
case 9:
return 4 //nine
case 10:
return 3 //ten
case 11:
return 6 //eleven
case 12:
return 6 //twelve
case 13:
return 8 //thirteen
case 14:
return 8 //fourteen
case 15:
return 7 //fifteen
case 16:
return 7 //sixteen
case 17:
return 9 //seventeen
case 18:
return 8 //eighteen
case 19:
return 8 //nineteen
case 20:
return 6 //twenty
case 30:
return 6 //thirty
case 40:
return 5 //forty
case 50:
return 5 //fifty
case 60:
return 5 //sixty
case 70:
return 7 //seventy
case 80:
return 6 //eighty
case 90:
return 6 //ninety
}
if number < 100 {
return lengthNumber(number-(number%10)) + lengthNumber(number%10)
}
if number%100 == 0 {
return lengthNumber(number/100) + 7
}
return lengthNumber(number/100) + 10 + lengthNumber(number%100)
}