From 1161f9a034de06a63538e3a9a0b7717098c744d9 Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Fri, 7 Apr 2023 08:13:49 -0500 Subject: Initial Commit --- Problem17.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Problem17.py (limited to 'Problem17.py') 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 -- cgit v1.2.3