From 16765a7a532e35394fd1788b4a7fefe372b8544f Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Wed, 23 Dec 2015 14:38:49 +0100 Subject: [PATCH] Added solution for problem 17 --- 17.py | 89 ++++++++++++++++++++++------------------------------------------------------------------- 1 file changed, 22 insertions(+), 67 deletions(-) diff --git a/17.py b/17.py index c23dd48..f8c28ce 100755 --- a/17.py +++ b/17.py @@ -1,67 +1,22 @@ -import sys; - -def getLetterNum(num): - switch(num): - if(num == 1): - return 3; - - elif(num == 2): - return 3; - - elif(num == 3): - return 5; - - elif(num == 4): - return 3; - - elif(num == 5): - return 3; - - elif(num == 6): - return 3; - - elif(num == 7): - return 3; - - elif(num == 8): - return 3; - - elif(num == 9): - return 3; - - elif(num == 10): - return 3; - - elif(num == 11): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - elif(num == 2): - return 3; - - -def countLetters(start, end): - count = 0; - for i in range(start, end+1): - count += getLetterNum(i); - return count; - -start = int(sys.argv[1]); -end = int(sys.argv[2]); -print "Result is " + str(countLetters(start,end)); +#!/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