From 467e15817d68236cb44e3d157f6f153ef161d3ba Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Tue, 21 Jul 2020 09:54:55 -0400 Subject: [PATCH] Updated run times and a few typos --- Problems/Problem1.py | 6 +++--- Problems/Problem10.py | 2 +- Problems/Problem11.py | 2 +- Problems/Problem12.py | 2 +- Problems/Problem13.py | 2 +- Problems/Problem14.py | 4 ++-- Problems/Problem15.py | 5 ++--- Problems/Problem16.py | 4 ++-- Problems/Problem17.py | 2 +- Problems/Problem18.py | 2 +- Problems/Problem19.py | 6 +++++- Problems/Problem2.py | 4 ++-- Problems/Problem20.py | 2 +- Problems/Problem21.py | 4 ++-- Problems/Problem22.py | 2 +- Problems/Problem23.py | 2 +- Problems/Problem24.py | 2 +- Problems/Problem25.py | 2 +- Problems/Problem26.py | 2 +- Problems/Problem27.py | 4 ++-- Problems/Problem28.py | 2 +- Problems/Problem29.py | 2 +- Problems/Problem3.py | 2 +- Problems/Problem30.py | 2 +- Problems/Problem31.py | 2 +- Problems/Problem4.py | 2 +- Problems/Problem5.py | 2 +- Problems/Problem6.py | 2 +- Problems/Problem67.py | 2 +- Problems/Problem7.py | 2 +- Problems/Problem8.py | 2 +- Problems/Problem9.py | 4 ++-- ProjectEuler.py | 2 ++ 33 files changed, 47 insertions(+), 42 deletions(-) diff --git a/Problems/Problem1.py b/Problems/Problem1.py index d7a5eb4..13a275a 100644 --- a/Problems/Problem1.py +++ b/Problems/Problem1.py @@ -63,7 +63,7 @@ class Problem1(Problem): self.solved = True #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 def reset(self): @@ -88,6 +88,6 @@ if(__name__ == "__main__"): print("It took " + problem.getTime() + " to solve this algorithm") """Results: -The sum of all the multiples of 3 or 5 is 233168 -It took 114.142 microseconds to run this algorithm +The sum of all numbers < 1000 is 233168 +It took an average of 102.336 microseconds to run this problem through 100 iterations """ diff --git a/Problems/Problem10.py b/Problems/Problem10.py index 21e9361..aa9ff16 100644 --- a/Problems/Problem10.py +++ b/Problems/Problem10.py @@ -86,5 +86,5 @@ if __name__ == "__main__": """Results: 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 """ diff --git a/Problems/Problem11.py b/Problems/Problem11.py index ede9dc3..5d71d34 100644 --- a/Problems/Problem11.py +++ b/Problems/Problem11.py @@ -188,5 +188,5 @@ if __name__ == "__main__": """Results: 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 """ diff --git a/Problems/Problem12.py b/Problems/Problem12.py index 753f227..713cb2b 100644 --- a/Problems/Problem12.py +++ b/Problems/Problem12.py @@ -115,5 +115,5 @@ if __name__ == "__main__": """Results: 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 """ diff --git a/Problems/Problem13.py b/Problems/Problem13.py index 42d34ec..c86cba3 100644 --- a/Problems/Problem13.py +++ b/Problems/Problem13.py @@ -290,5 +290,5 @@ if __name__ == "__main__": """Results: The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672 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 """ diff --git a/Problems/Problem14.py b/Problems/Problem14.py index 033bf0f..735e0d7 100644 --- a/Problems/Problem14.py +++ b/Problems/Problem14.py @@ -112,6 +112,6 @@ if __name__ == "__main__": print("It took " + problem.getTime() + " to solve this algorithm") """Results: -The longest chain with a starting number < 1000000 is 837799 with a length of 525 -It took 28.893 seconds to run this algorithm +The number 837799 produced a chain of 525 steps +It took an average of 26.591 seconds to run this problem through 100 iterations """ diff --git a/Problems/Problem15.py b/Problems/Problem15.py index 6b4016d..e35e0a2 100644 --- a/Problems/Problem15.py +++ b/Problems/Problem15.py @@ -4,8 +4,6 @@ #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? #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 @@ -101,5 +99,6 @@ if __name__ == "__main__": print("It took " + problem.getTime() + " to solve this algorithm") """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 """ diff --git a/Problems/Problem16.py b/Problems/Problem16.py index 46a3c8f..f8395f4 100644 --- a/Problems/Problem16.py +++ b/Problems/Problem16.py @@ -98,6 +98,6 @@ if __name__ == "__main__": """Results: 2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 -The sum of the digits is: 1366 -It took 86.206 microseconds to run this algorithm +The sum of the elements is 1366 +It took an average of 57.271 microseconds to run this problem through 100 iterations """ diff --git a/Problems/Problem17.py b/Problems/Problem17.py index 70af8ac..21be446 100644 --- a/Problems/Problem17.py +++ b/Problems/Problem17.py @@ -204,5 +204,5 @@ if __name__ == "__main__": """Results: 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 """ diff --git a/Problems/Problem18.py b/Problems/Problem18.py index a870765..e2b00e5 100644 --- a/Problems/Problem18.py +++ b/Problems/Problem18.py @@ -190,5 +190,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem19.py b/Problems/Problem19.py index be105c4..4195d3b 100644 --- a/Problems/Problem19.py +++ b/Problems/Problem19.py @@ -168,6 +168,10 @@ class Problem19(Problem): elif((year % 4) == 0): return True return False + #Reset the problem so it can be run again + def reset(self): + super().reset() + self.totalSundays = 0 #Gets #Returns the total sundays that were asked for @@ -190,5 +194,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem2.py b/Problems/Problem2.py index 9878d39..faa7768 100644 --- a/Problems/Problem2.py +++ b/Problems/Problem2.py @@ -60,7 +60,7 @@ class Problem2(Problem): self.timer.stop() #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 self.solved = True @@ -88,5 +88,5 @@ if __name__ == '__main__': """Results: 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 """ diff --git a/Problems/Problem20.py b/Problems/Problem20.py index a4ab912..1655a4f 100644 --- a/Problems/Problem20.py +++ b/Problems/Problem20.py @@ -98,5 +98,5 @@ if __name__ == "__main__": """ Results: 100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 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 """ diff --git a/Problems/Problem21.py b/Problems/Problem21.py index fb84fc6..c7d2066 100644 --- a/Problems/Problem21.py +++ b/Problems/Problem21.py @@ -72,7 +72,7 @@ class Problem21(Problem): self.timer.stop() #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: self.result += str(num) + '\n' 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 6368 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 """ diff --git a/Problems/Problem22.py b/Problems/Problem22.py index 2a9dea7..5ce1dfc 100644 --- a/Problems/Problem22.py +++ b/Problems/Problem22.py @@ -468,5 +468,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem23.py b/Problems/Problem23.py index 6d3ce91..2bdb42c 100644 --- a/Problems/Problem23.py +++ b/Problems/Problem23.py @@ -124,5 +124,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem24.py b/Problems/Problem24.py index 98a8250..26bcfa8 100644 --- a/Problems/Problem24.py +++ b/Problems/Problem24.py @@ -92,5 +92,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem25.py b/Problems/Problem25.py index 73e3368..a211247 100644 --- a/Problems/Problem25.py +++ b/Problems/Problem25.py @@ -95,5 +95,5 @@ if __name__ == "__main__": """ Results: The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816 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 """ diff --git a/Problems/Problem26.py b/Problems/Problem26.py index aba7079..991ba89 100644 --- a/Problems/Problem26.py +++ b/Problems/Problem26.py @@ -122,5 +122,5 @@ if __name__ == "__main__": """ Results: The longest cycle is 982 digits long 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 """ diff --git a/Problems/Problem27.py b/Problems/Problem27.py index a800a0c..eb2cbbf 100644 --- a/Problems/Problem27.py +++ b/Problems/Problem27.py @@ -83,7 +83,7 @@ class Problem27(Problem): super().reset() self.topA = 0 self.topB = 0 - self.topB = 0 + self.topN = 0 self.primes.clear() #Gets @@ -120,5 +120,5 @@ if __name__ == "__main__": The greatest number of primes found is 70 It was found with A = -61, B = 971 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 """ diff --git a/Problems/Problem28.py b/Problems/Problem28.py index ee5a409..b154f9a 100644 --- a/Problems/Problem28.py +++ b/Problems/Problem28.py @@ -148,5 +148,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem29.py b/Problems/Problem29.py index f76d546..1ca3dd1 100644 --- a/Problems/Problem29.py +++ b/Problems/Problem29.py @@ -117,5 +117,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem3.py b/Problems/Problem3.py index 3db5606..eddf646 100644 --- a/Problems/Problem3.py +++ b/Problems/Problem3.py @@ -96,5 +96,5 @@ if __name__ == '__main__': """Results: 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 """ diff --git a/Problems/Problem30.py b/Problems/Problem30.py index 75de59c..053b956 100644 --- a/Problems/Problem30.py +++ b/Problems/Problem30.py @@ -116,5 +116,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem31.py b/Problems/Problem31.py index c0f3f19..cbdbd4c 100644 --- a/Problems/Problem31.py +++ b/Problems/Problem31.py @@ -91,5 +91,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem4.py b/Problems/Problem4.py index c676005..2fa68f5 100644 --- a/Problems/Problem4.py +++ b/Problems/Problem4.py @@ -99,5 +99,5 @@ if __name__ == '__main__': """Results: 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 """ diff --git a/Problems/Problem5.py b/Problems/Problem5.py index 32fba81..af3e459 100644 --- a/Problems/Problem5.py +++ b/Problems/Problem5.py @@ -103,5 +103,5 @@ if __name__ == '__main__': """Results: 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 """ \ No newline at end of file diff --git a/Problems/Problem6.py b/Problems/Problem6.py index 1d2dc30..a4bc40f 100644 --- a/Problems/Problem6.py +++ b/Problems/Problem6.py @@ -102,5 +102,5 @@ if __name__ == '__main__': """Results: 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 """ diff --git a/Problems/Problem67.py b/Problems/Problem67.py index 35b3d9f..2707322 100644 --- a/Problems/Problem67.py +++ b/Problems/Problem67.py @@ -360,5 +360,5 @@ if __name__ == "__main__": """ Results: 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 """ diff --git a/Problems/Problem7.py b/Problems/Problem7.py index 7336a45..c4941fc 100644 --- a/Problems/Problem7.py +++ b/Problems/Problem7.py @@ -83,5 +83,5 @@ if __name__ == '__main__': """Results: 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 """ diff --git a/Problems/Problem8.py b/Problems/Problem8.py index cecbe46..4cc71ab 100644 --- a/Problems/Problem8.py +++ b/Problems/Problem8.py @@ -122,5 +122,5 @@ if __name__ == '__main__': """Results: The largest product of 13 adjacent digits in the number is 23514624000 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 """ diff --git a/Problems/Problem9.py b/Problems/Problem9.py index e78739e..c8d7507 100644 --- a/Problems/Problem9.py +++ b/Problems/Problem9.py @@ -84,7 +84,7 @@ class Problem9(Problem): self.a = 1 self.b = 0 self.c = 0 - found = False + self.found = False #Gets #Returns the length of the first side @@ -124,5 +124,5 @@ if __name__ == "__main__": """Results: The Pythagorean triplet where a + b + c = 1000 is 200 375 425 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 """ diff --git a/ProjectEuler.py b/ProjectEuler.py index acff20c..ccfa6ab 100644 --- a/ProjectEuler.py +++ b/ProjectEuler.py @@ -1,2 +1,4 @@ +#!/bin/python3 + from Driver import Driver Driver.main()