From 46b4e51d6e027905a3ae1530dc0dfbfee644ab91 Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Sun, 18 Mar 2018 13:59:01 -0400 Subject: [PATCH 1/3] Solution to Problem 48 --- Project Euler/Problem 48/sol1.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Project Euler/Problem 48/sol1.py diff --git a/Project Euler/Problem 48/sol1.py b/Project Euler/Problem 48/sol1.py new file mode 100644 index 000000000..5c4bdb0f6 --- /dev/null +++ b/Project Euler/Problem 48/sol1.py @@ -0,0 +1,21 @@ +from __future__ import print_function +''' +Self Powers +Problem 48 + +The series, 11 + 22 + 33 + ... + 1010 = 10405071317. + +Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000. +''' + +try: + xrange +except NameError: + xrange = range + +total = 0 +for i in xrange(1, 1001): + total += i**i + + +print(str(total)[-10:]) \ No newline at end of file From 689e93439a9e8837e2597a814a0c4b3dc81c241c Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Sun, 18 Mar 2018 17:44:18 -0400 Subject: [PATCH 2/3] Solution to Problem 17 --- Project Euler/Problem 17/sol1.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Project Euler/Problem 17/sol1.py diff --git a/Project Euler/Problem 17/sol1.py b/Project Euler/Problem 17/sol1.py new file mode 100644 index 000000000..3baf0f9f7 --- /dev/null +++ b/Project Euler/Problem 17/sol1.py @@ -0,0 +1,35 @@ +from __future__ import print_function +''' +Number letter counts +Problem 17 + +If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. + +If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? + + +NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) +contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage. +''' + +ones_counts = [0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8] #number of letters in zero, one, two, ..., nineteen (0 for zero since its never said aloud) +tens_counts = [0, 0, 6, 6, 5, 5, 5, 7, 6, 6] #number of letters in twenty, thirty, ..., ninety (0 for numbers less than 20 due to inconsistency in teens) + +count = 0 + +for i in range(1, 1001): + if i < 1000: + if i >= 100: + count += ones_counts[i/100] + 7 #add number of letters for "n hundred" + + if i%100 is not 0: + count += 3 #add number of letters for "and" if number is not multiple of 100 + + if 0 < i%100 < 20: + count += ones_counts[i%100] #add number of letters for one, two, three, ..., nineteen (could be combined with below if not for inconsistency in teens) + else: + count += ones_counts[i%10] + tens_counts[(i%100-i%10)/10] #add number of letters for twenty, twenty one, ..., ninety nine + else: + count += ones_counts[i/1000] + 8 + +print(count) \ No newline at end of file From 2d2644ee1761dbd98e9e8ba7e1545666709248c4 Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Sun, 18 Mar 2018 17:45:28 -0400 Subject: [PATCH 3/3] Solution to Problem 17 --- Project Euler/Problem 17/sol1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project Euler/Problem 17/sol1.py b/Project Euler/Problem 17/sol1.py index 3baf0f9f7..9de5d80b9 100644 --- a/Project Euler/Problem 17/sol1.py +++ b/Project Euler/Problem 17/sol1.py @@ -12,7 +12,7 @@ NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty- contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage. ''' -ones_counts = [0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8] #number of letters in zero, one, two, ..., nineteen (0 for zero since its never said aloud) +ones_counts = [0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8] #number of letters in zero, one, two, ..., nineteen (0 for zero since it's never said aloud) tens_counts = [0, 0, 6, 6, 5, 5, 5, 7, 6, 6] #number of letters in twenty, thirty, ..., ninety (0 for numbers less than 20 due to inconsistency in teens) count = 0