diff options
Diffstat (limited to 'Problem17.py')
-rw-r--r-- | Problem17.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Problem17.py b/Problem17.py new file mode 100644 index 0000000..a220e88 --- /dev/null +++ b/Problem17.py @@ -0,0 +1,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)
\ No newline at end of file |