This file contains hidden or 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
| from math import sqrt | |
| from decimal import * | |
| # you need more than 100 digits, b/c otherwise you get rounding errors | |
| getcontext().prec = 105 | |
| squares=[] | |
| for a in range (2,10): | |
| squares.append(a**2) | |
| total=0 |
This file contains hidden or 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=78 | |
| from math import floor,sqrt | |
| def pent(n): | |
| return ((3*n*n)-n) / 2 | |
| def sign(x): | |
| a = floor(x/2) | |
| if a%2 == 0: | |
| return 1 |
This file contains hidden or 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=77 | |
| # i couldn't find a recursive generating function like i used for #76 | |
| # one exists, http://mathworld.wolfram.com/EulerTransform.html - but i couldn't figure it out | |
| # so i had to go back to the change counting problem, #31, and repurpose one of those functions | |
| for x in range (11,80): | |
| coins=[] | |
| # generate primes for coin algorithm | |
| n=x+1 |
This file contains hidden or 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=76 | |
| # we'll use euler's formula for generating the partition series | |
| def pent(n): | |
| return ((3*n*n)-n) / 2 | |
| def p(k): | |
| if k in dict: | |
| return dict[k] | |
| elif k == 0: |
This file contains hidden or 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=75 | |
| def generatora(a,b,c): | |
| if a+b+c <= 1500000: | |
| global count | |
| k=1 | |
| while k*(a+b+c) <= 1500000: | |
| count[k*(a+b+c)]+=1 | |
| k+=1 | |
| aa = a-2*b+2*c |
This file contains hidden or 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
| from math import factorial | |
| def fadd(n): | |
| sum = 0 | |
| for i in range (0,len(str(n))): | |
| sum += factorial(int(str(n)[i:i+1])) | |
| return sum | |
| def roundfadd(n,array,p): | |
| if n in sequences: |
This file contains hidden or 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=73 | |
| from fractions import Fraction, gcd | |
| count=0 | |
| # start at 5, b/c that's the first number that has a fraction in this range | |
| for d in range (5,12001): | |
| for e in range (d/3,d/2): | |
| if gcd(e,d) == 1: | |
| count+=1 |
This file contains hidden or 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=72 | |
| # i got to thinking that this is really just asking to take a sum of euleur's totient from 2 to 1MM | |
| # and that turns out to be true. | |
| factors = [1]*1000001 | |
| for i in range (0,len(factors)): | |
| factors[i]=i | |
| # set up prime sieve to n |
This file contains hidden or 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
| from fractions import Fraction, gcd | |
| from math import floor | |
| # n /d < 3/7 | |
| # so n < d*(3/7) | |
| # so for each denominator, we'll look for the closest n that satisfies this equation | |
| # if n and d have gcd==1, then they're a reduced fraction | |
| # and the last one should be the closest fraction to 3/7 under 1MM | |
| for d in range (1,1000000): |
This file contains hidden or 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
| factors = [1]*10000001 | |
| for i in range (0,len(factors)): | |
| factors[i]=i | |
| # set up prime sieve to n | |
| n=10000000 | |
| myPrimes = [True]*(n+1) | |
| last = 0 | |
| for i in range (2,n): |