Commit 28c8dda08543febf3269d9735535f70885bf980f
1 parent
64c1eaf4
Added problem 17
Showing
1 changed file
with
22 additions
and
0 deletions
17.py
0 → 100644
1 | +#!/usr/bin/python | ||
2 | + | ||
3 | +S = [0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8] | ||
4 | +D = [0,3,6,6,5,5,5,7,6,6] | ||
5 | +H = 7 | ||
6 | +T = 8 | ||
7 | + | ||
8 | +total = 0 | ||
9 | +for i in range(1,1000): | ||
10 | + c = i % 10 # singles digit | ||
11 | + b = ((i % 100) - c) / 10 # tens digit | ||
12 | + a = ((i % 1000) - (b * 10) - c) / 100 # hundreds digit | ||
13 | + | ||
14 | + if a != 0: | ||
15 | + total += S[a] + H # "S[a] hundred | ||
16 | + if b != 0 or c != 0: total += 3 # "and" | ||
17 | + if b == 0 or b == 1: total += S[b * 10 + c] | ||
18 | + else: total += D[b] + S[c] | ||
19 | + | ||
20 | +total += S[1] + T | ||
21 | + | ||
22 | +print "Result is: " + str(total) |