From 28c8dda08543febf3269d9735535f70885bf980f Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Wed, 23 Dec 2015 14:41:01 +0100 Subject: [PATCH] Added problem 17 --- 17.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+), 0 deletions(-) create mode 100644 17.py diff --git a/17.py b/17.py new file mode 100644 index 0000000..f8c28ce --- /dev/null +++ b/17.py @@ -0,0 +1,22 @@ +#!/usr/bin/python + +S = [0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8] +D = [0,3,6,6,5,5,5,7,6,6] +H = 7 +T = 8 + +total = 0 +for i in range(1,1000): + c = i % 10 # singles digit + b = ((i % 100) - c) / 10 # tens digit + a = ((i % 1000) - (b * 10) - c) / 100 # hundreds digit + + if a != 0: + total += S[a] + H # "S[a] hundred + if b != 0 or c != 0: total += 3 # "and" + if b == 0 or b == 1: total += S[b * 10 + c] + else: total += D[b] + S[c] + +total += S[1] + T + +print "Result is: " + str(total) -- libgit2 0.22.2