mirror of
https://bitbucket.org/Mattrixwv/projecteulerpython.git
synced 2025-12-06 17:43:58 -05:00
Updated run times and a few typos
This commit is contained in:
@@ -63,7 +63,7 @@ class Problem1(Problem):
|
|||||||
self.solved = True
|
self.solved = True
|
||||||
|
|
||||||
#Save the results
|
#Save the results
|
||||||
self.result = "The sum of all number < " + str(self.__topNum + 1) + " is " + str(self.fullSum)
|
self.result = "The sum of all numbers < " + str(self.__topNum + 1) + " is " + str(self.fullSum)
|
||||||
|
|
||||||
#Reset the problem so it can be run again
|
#Reset the problem so it can be run again
|
||||||
def reset(self):
|
def reset(self):
|
||||||
@@ -88,6 +88,6 @@ if(__name__ == "__main__"):
|
|||||||
print("It took " + problem.getTime() + " to solve this algorithm")
|
print("It took " + problem.getTime() + " to solve this algorithm")
|
||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The sum of all the multiples of 3 or 5 is 233168
|
The sum of all numbers < 1000 is 233168
|
||||||
It took 114.142 microseconds to run this algorithm
|
It took an average of 102.336 microseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -86,5 +86,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The sum of all the prime numbers less than 2000000 is 142913828922
|
The sum of all the prime numbers less than 2000000 is 142913828922
|
||||||
It took 5.926 seconds to run this algorithm
|
It took an average of 7.187 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -188,5 +188,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The greatest product of 3 numbers in a line is 70600674
|
The greatest product of 3 numbers in a line is 70600674
|
||||||
It took 1.162 milliseconds to run this algorithm
|
It took an average of 1.071 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -115,5 +115,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The first triangular number with more than 500 divisors is 76576500
|
The first triangular number with more than 500 divisors is 76576500
|
||||||
It took 2.898 seconds to run this algorithm
|
It took an average of 5.932 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -290,5 +290,5 @@ if __name__ == "__main__":
|
|||||||
"""Results:
|
"""Results:
|
||||||
The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672
|
The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672
|
||||||
The first 10 digits are: 5537376230
|
The first 10 digits are: 5537376230
|
||||||
It took 23.015 microseconds to run this algorithm
|
It took an average of 2.694 microseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -112,6 +112,6 @@ if __name__ == "__main__":
|
|||||||
print("It took " + problem.getTime() + " to solve this algorithm")
|
print("It took " + problem.getTime() + " to solve this algorithm")
|
||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The longest chain with a starting number < 1000000 is 837799 with a length of 525
|
The number 837799 produced a chain of 525 steps
|
||||||
It took 28.893 seconds to run this algorithm
|
It took an average of 26.591 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
#Modified: 07-18-20
|
#Modified: 07-18-20
|
||||||
#How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down?
|
#How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down?
|
||||||
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
|
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
|
||||||
#There must be a better way than this. This is untested. I let it run for about 14 hours and it still hadn't spit an answer out for me
|
|
||||||
#But it is programed exactly as I programmed the C++ solution, so the eventual answer should be correct
|
|
||||||
"""
|
"""
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2020 Matthew Ellison
|
||||||
|
|
||||||
@@ -101,5 +99,6 @@ if __name__ == "__main__":
|
|||||||
print("It took " + problem.getTime() + " to solve this algorithm")
|
print("It took " + problem.getTime() + " to solve this algorithm")
|
||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
|
The number of paths from 1 corner of a 20 x 20 grid to the opposite corner is 137846528820
|
||||||
|
It took 32.903 hours to solve this algorithm
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -98,6 +98,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
|
2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
|
||||||
The sum of the digits is: 1366
|
The sum of the elements is 1366
|
||||||
It took 86.206 microseconds to run this algorithm
|
It took an average of 57.271 microseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -204,5 +204,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The sum of all the letters in all the numbers 1-1000 is 21124
|
The sum of all the letters in all the numbers 1-1000 is 21124
|
||||||
It took 4.107 milliseconds to run this algorithm
|
It took an average of 3.095 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -190,5 +190,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
The value of the longest path is 1074
|
The value of the longest path is 1074
|
||||||
It took 654.691 microseconds to run this algorithm
|
It took an average of 422.974 microseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -168,6 +168,10 @@ class Problem19(Problem):
|
|||||||
elif((year % 4) == 0):
|
elif((year % 4) == 0):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
#Reset the problem so it can be run again
|
||||||
|
def reset(self):
|
||||||
|
super().reset()
|
||||||
|
self.totalSundays = 0
|
||||||
|
|
||||||
#Gets
|
#Gets
|
||||||
#Returns the total sundays that were asked for
|
#Returns the total sundays that were asked for
|
||||||
@@ -190,5 +194,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
There are 171 Sundays that landed on the first of the month from 1901 to 2000
|
There are 171 Sundays that landed on the first of the month from 1901 to 2000
|
||||||
It took 724.930 milliseconds to run this algorithm
|
It took an average of 386.694 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class Problem2(Problem):
|
|||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
|
|
||||||
#Save the results
|
#Save the results
|
||||||
self.result = "The sum of all even Fibonacci numbers less than " + str(self.__topNumber) + " is " + str(self.fullSum)
|
self.result = "The sum of all even Fibonacci numbers less than " + str(self.__topNumber + 1) + " is " + str(self.fullSum)
|
||||||
|
|
||||||
#Throw a flag to show the problem is solved
|
#Throw a flag to show the problem is solved
|
||||||
self.solved = True
|
self.solved = True
|
||||||
@@ -88,5 +88,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The sum of all even Fibonacci numbers less than 4000000 is 4613732
|
The sum of all even Fibonacci numbers less than 4000000 is 4613732
|
||||||
It took 27.621 microseconds to run this algorithm
|
It took an average of 10.286 microseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -98,5 +98,5 @@ if __name__ == "__main__":
|
|||||||
""" Results:
|
""" Results:
|
||||||
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
|
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
|
||||||
The sum of the digits is: 648
|
The sum of the digits is: 648
|
||||||
It took 99.670 microseconds to run this algorithm
|
It took an average of 36.938 microseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class Problem21(Problem):
|
|||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
|
|
||||||
#Save the results
|
#Save the results
|
||||||
self.result += "All amicable numbers less than 10000 are"
|
self.result += "All amicable numbers less than 10000 are\n"
|
||||||
for num in self.amicable:
|
for num in self.amicable:
|
||||||
self.result += str(num) + '\n'
|
self.result += str(num) + '\n'
|
||||||
self.result += "The sum of all of these amicable numbers is " + str(sum(self.amicable))
|
self.result += "The sum of all of these amicable numbers is " + str(sum(self.amicable))
|
||||||
@@ -121,5 +121,5 @@ All amicable numbers less than 10000 are
|
|||||||
6232
|
6232
|
||||||
6368
|
6368
|
||||||
The sum of all of these amicable numbers is 31626
|
The sum of all of these amicable numbers is 31626
|
||||||
It took 59.496 milliseconds to run this algorithm
|
It took an average of 54.769 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -468,5 +468,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
The answer to the question is 871198282
|
The answer to the question is 871198282
|
||||||
It took 9.206 milliseconds to run this algorithm
|
It took an average of 6.343 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -124,5 +124,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
The answer is 4179871
|
The answer is 4179871
|
||||||
It took 27.738 minutes to run this algorithm
|
It took an average of 24.184 minutes to run this problem through 10 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -92,5 +92,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
The 1 millionth permutation is 2783915460
|
The 1 millionth permutation is 2783915460
|
||||||
It took 7.363 seconds to run this algorithm
|
It took an average of 7.147 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -95,5 +95,5 @@ if __name__ == "__main__":
|
|||||||
""" Results:
|
""" Results:
|
||||||
The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
|
The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
|
||||||
Its index is 4782
|
Its index is 4782
|
||||||
It took 4.216 seconds to run this algorithm
|
It took an average of 3.337 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -122,5 +122,5 @@ if __name__ == "__main__":
|
|||||||
""" Results:
|
""" Results:
|
||||||
The longest cycle is 982 digits long
|
The longest cycle is 982 digits long
|
||||||
It is started with the number 983
|
It is started with the number 983
|
||||||
It took 182.704 milliseconds to run this algorithm
|
It took an average of 139.229 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class Problem27(Problem):
|
|||||||
super().reset()
|
super().reset()
|
||||||
self.topA = 0
|
self.topA = 0
|
||||||
self.topB = 0
|
self.topB = 0
|
||||||
self.topB = 0
|
self.topN = 0
|
||||||
self.primes.clear()
|
self.primes.clear()
|
||||||
|
|
||||||
#Gets
|
#Gets
|
||||||
@@ -120,5 +120,5 @@ if __name__ == "__main__":
|
|||||||
The greatest number of primes found is 70
|
The greatest number of primes found is 70
|
||||||
It was found with A = -61, B = 971
|
It was found with A = -61, B = 971
|
||||||
The product of A and B is -59231
|
The product of A and B is -59231
|
||||||
It took 35.775 seconds to run this algorithm
|
It took an average of 49.963 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -148,5 +148,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
The sum of the diagonals in the given grid is 669171001
|
The sum of the diagonals in the given grid is 669171001
|
||||||
It took 197.764 milliseconds to run this algorithm
|
It took an average of 212.747 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -117,5 +117,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
The number of unique values generated by a^b for 2 <= a < = 100 and 2 <= b <= 100 is 9183
|
The number of unique values generated by a^b for 2 <= a < = 100 and 2 <= b <= 100 is 9183
|
||||||
It took 304.630 milliseconds to run this algorithm
|
It took an average of 304.306 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -96,5 +96,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The largest prime factor of 600851475143 is 6857
|
The largest prime factor of 600851475143 is 6857
|
||||||
It took 1.685 seconds to run this algorithm
|
It took an average of 2.084 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -116,5 +116,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839
|
The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839
|
||||||
It took 3.284 seconds to run this algorithm
|
It took an average of 4.068 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -91,5 +91,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
There are 73682 ways to make 2 pounds with the given denominations of coins
|
There are 73682 ways to make 2 pounds with the given denominations of coins
|
||||||
It took 2.653 milliseconds to run this algorithm
|
It took an average of 5.519 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -99,5 +99,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The largest palindrome made from the product of two 3-digit numbers is 906609
|
The largest palindrome made from the product of two 3-digit numbers is 906609
|
||||||
It took 177.314 milliseconds to run this algorithm
|
It took an average of 149.187 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -103,5 +103,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The smallest positive number that is evenly divisible by all numbers 1-20 is 232792560
|
The smallest positive number that is evenly divisible by all numbers 1-20 is 232792560
|
||||||
It took 50.236 seconds to run this algorithm
|
It took an average of 54.833 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
@@ -102,5 +102,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The difference between the sum of the squares and the square of the sum of the numbers 1-100 is 25164150
|
The difference between the sum of the squares and the square of the sum of the numbers 1-100 is 25164150
|
||||||
It took 24.384 microseconds to run this algorithm
|
It took an average of 14.266 microseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -360,5 +360,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
""" Results:
|
""" Results:
|
||||||
The value of the longest path is 7273
|
The value of the longest path is 7273
|
||||||
It took 16.483 seconds to run this algorithm
|
It took an average of 8.244 seconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -83,5 +83,5 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
The 10001th prime number is 104743
|
The 10001th prime number is 104743
|
||||||
It took 139.545 milliseconds to run this algorithm
|
It took an average of 109.101 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -122,5 +122,5 @@ if __name__ == '__main__':
|
|||||||
"""Results:
|
"""Results:
|
||||||
The largest product of 13 adjacent digits in the number is 23514624000
|
The largest product of 13 adjacent digits in the number is 23514624000
|
||||||
The numbers are: 5576689664895
|
The numbers are: 5576689664895
|
||||||
It took 2.593 milliseconds to run this algorithm
|
It took an average of 2.024 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Problem9(Problem):
|
|||||||
self.a = 1
|
self.a = 1
|
||||||
self.b = 0
|
self.b = 0
|
||||||
self.c = 0
|
self.c = 0
|
||||||
found = False
|
self.found = False
|
||||||
|
|
||||||
#Gets
|
#Gets
|
||||||
#Returns the length of the first side
|
#Returns the length of the first side
|
||||||
@@ -124,5 +124,5 @@ if __name__ == "__main__":
|
|||||||
"""Results:
|
"""Results:
|
||||||
The Pythagorean triplet where a + b + c = 1000 is 200 375 425
|
The Pythagorean triplet where a + b + c = 1000 is 200 375 425
|
||||||
The product of those numbers is 31875000
|
The product of those numbers is 31875000
|
||||||
It took 22.106 milliseconds to run this algorithm
|
It took an average of 36.729 milliseconds to run this problem through 100 iterations
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
|
#!/bin/python3
|
||||||
|
|
||||||
from Driver import Driver
|
from Driver import Driver
|
||||||
Driver.main()
|
Driver.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user