This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://projecteuler.net/problem=94 | |
# we're going to solve this using diophantine equations | |
# first convert area formula to -3a**2-2a+4c**2+1=0 and -3a**2+2a+4c**2+1=0 | |
# then run that through this solver http://www.alpertron.com.ar/QUAD.HTM to get 2 recursive equations | |
limit = 1000000000 | |
sum = 0 | |
# a-1 case | |
a = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://projecteuler.net/problem=100 | |
# algabraic rearrangement to 2b**2-2b-t**2+t = 0 (where b is blue balls, t is total balls) | |
# this is a diophantine equation, which can be solved recursively- to get formulas for next b,t: | |
# http://www.alpertron.com.ar/QUAD.HTM, put in coeeficients above - got that from Dreamshire | |
b = 85 | |
t = 120 | |
while t < 10**12: | |
# i learned that this allows you to set both at once so you don't have to use an intermediate variable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://projecteuler.net/problem=85 | |
# notes- formula to count boxes is just x * x+1 / 2 * y * y+1 /2 | |
# this is triangle number x * triangle number y | |
def triangle(n): | |
return n*(n+1)/2 | |
# i found the ranges by trial and error, starting at 100 each | |
min = 2000000 | |
for a in range (0,37): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://projecteuler.net/problem=95 | |
# brute force sieve | |
n=1000000 | |
sequences = {} | |
divisorSum = [1]*(n+1) | |
for i in range (2,n/2+1): | |
j = 2*i | |
while j<=n: | |
divisorSum[j]+=i | |
j = j+i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://projecteuler.net/problem=87 | |
# set up prime sieve to 50MM**.25 | |
n=7100 | |
myPrimes = [True]*(n+1) | |
last = 0 | |
for i in range (2,n): | |
if myPrimes[i] == True: | |
j = 2*i | |
while j<=n: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is the simplest way- show all but the last 10 digits | |
print str(28433*pow(2,7830457)+1)[2357197:] | |
# which is equivalent to | |
print (28433 * 2**7830457 + 1) % 10000000000 | |
# which is equivalent to | |
print (28433 * pow(2, 7830457) + 1) % 10**10 | |
# which is equivalent to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://projecteuler.net/problem=99 | |
from math import log | |
file = open('base_exp.txt','r').readlines() | |
# i thought maybe if we worked the box in two sections- from the top down and from the bottom up | |
# meeting in the middle, where the target cell was- but this doesn't appear to work either | |
array = [] | |
for i in range (0,len(file)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://projecteuler.net/problem=92 | |
# this version takes advantage of the fact that all numbers up to 10MM have roundfadds < 600 | |
# so first compute those, then check them for each number from 1 to 10MM | |
# that shaves it from 6 minutes to 120s | |
def fadd(n): | |
sum = 0 | |
for i in range (0,len(str(n))): | |
sum += int(str(n)[i:i+1])**2 | |
return sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file = open('matrix2.txt','r').readlines() | |
# i thought maybe if we worked the box in two sections- from the top down and from the bottom up | |
# meeting in the middle, where the target cell was- but this doesn't appear to work either | |
array = [] | |
for i in range (0,len(file)): | |
line = file[i].split(',') | |
array.append(line) | |
n = len(array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file = open('matrix.txt','r').readlines() | |
array = [] | |
for i in range (0,len(file)): | |
line = file[i].split(',') | |
array.append(line) | |
#adding algorithm works backward from next to last row to 0 row | |
for r in range (79,-1,-1): | |
for s in range (79,-1,-1): |
NewerOlder