diff options
author | mjfernez <mjfernez@gmail.com> | 2020-02-03 19:49:58 -0500 |
---|---|---|
committer | mjfernez <mjfernez@gmail.com> | 2020-02-03 19:49:58 -0500 |
commit | e6a7399134b3dc08f9e6e9c9c74e39ac449b8538 (patch) | |
tree | 2cd7b6ba1a10562d219028aa84aedfc49d872761 | |
parent | d62ba829dc3a54edc46b7deb581dd244713393f5 (diff) | |
download | Project_Euler_Solutions-e6a7399134b3dc08f9e6e9c9c74e39ac449b8538.tar.gz |
Fix dumb mistakes
-rw-r--r-- | 10001prime.py | 7 | ||||
-rw-r--r-- | bigfactors2.py | 5 | ||||
-rw-r--r-- | collatz.py | 5 | ||||
-rw-r--r-- | palindrome.py | 5 | ||||
-rw-r--r-- | productofdigits.py | 6 | ||||
-rw-r--r-- | productofgrid.py | 21 | ||||
-rw-r--r-- | smallmult.py | 5 | ||||
-rw-r--r-- | sumexp.py | 4 | ||||
-rw-r--r-- | sumofprimes.py | 5 | ||||
-rw-r--r-- | sumsq.py | 13 |
10 files changed, 25 insertions, 51 deletions
diff --git a/10001prime.py b/10001prime.py index ecf8139..ecaa8cd 100644 --- a/10001prime.py +++ b/10001prime.py @@ -1,5 +1,4 @@ import PIL, math -import numpy as np #Problem 7 - 10,001st prime @@ -8,7 +7,7 @@ def listprimes(number): primes = [] if (number <=1): return [1] - a = np.ones(number) + a = [1] * number a[0]=0 a[1]=0#1 and 0 are not prime ##Sieve of eratosthenes @@ -26,6 +25,6 @@ def listprimes(number): return primes out_list = listprimes(1000000) -print out_list +#print(out_list) #return 10,001th prime factor -print out_list[10000] +print(out_list[10000]) diff --git a/bigfactors2.py b/bigfactors2.py index 5758019..41bc13d 100644 --- a/bigfactors2.py +++ b/bigfactors2.py @@ -1,5 +1,4 @@ import PIL, math -import numpy as np #Problem 12 Highly divisible triangular number #finds the first number with over 500 factors @@ -27,5 +26,7 @@ j = 0 while(k < 500): j += i k=countfactors(j) - print str(j) + " has " + str(k) + " factors" + print(str(j) + " has " + str(k) + " factors") i += 1 + +print("Ding! Ding! {} has over 500 factors, wow!".format(j)) @@ -1,5 +1,4 @@ import PIL, math -import numpy as np #Problem 14 Longest Collatz sequence #Note, a little slow, takes about 15 seconds. @@ -21,5 +20,5 @@ for n in range(1,pow(10,6)): if(len(chain)>len(biggo)): biggo = chain chain = [] -print biggo -print "Has " + str(len(biggo)) +" numbers." +print(biggo) +print("Has " + str(len(biggo)) +" numbers.") diff --git a/palindrome.py b/palindrome.py index c581a72..9690553 100644 --- a/palindrome.py +++ b/palindrome.py @@ -1,5 +1,4 @@ import PIL, math -import numpy as np #Problem 4 - Palindrome Products @@ -29,8 +28,8 @@ def findMaxPalindrome(): return large answer = findMaxPalindrome() -print answer -print "The factors are: " + str(findProduct(answer)) +print(answer) +print("The factors are: " + str(findProduct(answer))) #x = input("Type a palindromic number: ") #if(isPalindrome(x)): diff --git a/productofdigits.py b/productofdigits.py index d05b757..ddd5edc 100644 --- a/productofdigits.py +++ b/productofdigits.py @@ -2,6 +2,8 @@ import PIL, math import numpy as np #Problem 8 - largest Product in a series +bigBoy=7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450 + def parseNum(x, r): search = str(x) maxi = 0 @@ -13,6 +15,4 @@ def parseNum(x, r): maxi = prod return maxi -bigBoy=7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450 - -print parseNum(bigBoy, 13) +print(parseNum(bigBoy, 13)) diff --git a/productofgrid.py b/productofgrid.py deleted file mode 100644 index ab54c40..0000000 --- a/productofgrid.py +++ /dev/null @@ -1,21 +0,0 @@ -import PIL, math -import numpy -from numpy import matrix - -##Problem 11 - Largest Product in a grid -def parseMatrix(x, r): - - maxi = 0 - for ch in range(0,len(search)-r): - prod = int(search[ch]) - for dig in range(ch+1, ch+r): - prod*=int(search[dig]) - if (prod > maxi): - maxi = prod - return maxi - -#bigBoy=7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450 - -mat = matrix([[08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08],[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00],[81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65],[52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91],[22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80],[24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50],[32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70],[67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 08, 40, 91, 66, 49, 94, 21],[24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72],[21, 36, 23, 09, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95],[78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 09, 53, 56, 92],[16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57],[86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58],[19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40],[04, 52, 08, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66],[88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69],[04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 08, 46, 29, 32, 40, 62, 76, 36],[20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16],[20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54],[01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48]]) -print mat[6,8] -#print parseMatrix(mat, 4 ) diff --git a/smallmult.py b/smallmult.py index 88c3dcc..d672ef0 100644 --- a/smallmult.py +++ b/smallmult.py @@ -5,7 +5,6 @@ #by all of the numbers from 1 to 20? import PIL, math -import numpy as np def isDivisible(num, divisors): divisible = True @@ -23,5 +22,5 @@ while (not found): start+=20 found = isDivisible(start,divs) -print start -print str(isDivisible(start, divs)) +print(start) +print(str(isDivisible(start, divs))) @@ -5,6 +5,6 @@ strn = str(n) s = 0 for i in strn: - s+=int(i) + s += int(i) -print s +print(s) diff --git a/sumofprimes.py b/sumofprimes.py index 7c1646b..3799e94 100644 --- a/sumofprimes.py +++ b/sumofprimes.py @@ -1,5 +1,4 @@ import PIL, math -import numpy as np #Problem 10 sum of primes ###INEFFICIENT### @@ -25,7 +24,7 @@ def prime_factors(number): primes = [] if (number <=1): return [1] - a = np.ones(number) + a = [1] * number a[0]=0 a[1]=0#not prime for i in range(2,int(math.ceil(math.sqrt(number)))): @@ -42,4 +41,4 @@ def prime_factors(number): return primes out = prime_factors(2000000) -print str(sum(out)) +print(str(sum(out))) @@ -8,21 +8,20 @@ #one hundred natural numbers and the square of the sum. import PIL, math -import numpy as np nums = range(1,11) numsq = range(1,11) for i in nums: - i = i*i + i = i*i -print nums -print numsq +print(nums) +print(numsq) sum1 = (sum(nums)**2) sum2 = (sum(numsq)) -print "The sum squared is: " + str(sum1) -print "The sum of the squares is: " + str(sum2) +print("The sum squared is: " + str(sum1)) +print("The sum of the squares is: " + str(sum2)) -print "The difference is: " + str(abs(sum2-sum1))
\ No newline at end of file +print("The difference is: " + str(abs(sum2-sum1))) |