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=58 | |
| # this is the same spiral from http://projecteuler.net/problem=28 | |
| # doing individual prime tests is faster than using a seive for numbers this large | |
| def is_prime(n): | |
| if n == 2 or n == 3: return True | |
| if n < 2 or n%2 == 0: return False | |
| if n < 9: return True | |
| if n%3 == 0: return False | |
| r = int(n**.5) |
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=58 | |
| # i found this confusing, so i worked through dreamshire's analysis | |
| # numerator is always = numerator + denominator * 2 | |
| # denominator is = numerator + denominator | |
| # starting with numerator 3 and denominator 2 | |
| # which is round 1, so start at round 2 | |
| numerator = 3 | |
| denominator = 2 |
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=57 | |
| # python is well suited to doing this through simple brute force | |
| max = 0 | |
| for a in range (1,100): | |
| for b in range (1,100): | |
| a2b = str(a**b) | |
| sum = 0 | |
| for x in range (0,len(a2b)): | |
| digit = int(a2b[x: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=56 | |
| # first, a few functions we'll use- i particularly like the reverse | |
| def reverse(string): | |
| string = string[::-1] | |
| return string | |
| def is_pali(string): | |
| if string==reverse(string): |
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
| # arrays for grading hands | |
| numbers = ["2","3","4","5","6","7","8","9","T","J","Q","K","A"] | |
| plays = ["0P","1P","2P","3K","4$","5F","6F","7F","8F","9F"] | |
| # some functions we'll use- the basic approach for the grade function | |
| # is to give each hand a string grade- when sorted, the better hand should come out on top | |
| def l2n(letter): | |
| index = numbers.index(letter)+2 |
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=53 | |
| # python has a lot of useful math functions! | |
| import math | |
| # it also has itertools, which can give us the exact combinations of a set | |
| # but here we're just calculating numbers, so i'll use the math factorial function | |
| count = 0 | |
| for n in range (2,101): |
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=52 | |
| # we'll use the python built-in permutation function | |
| import itertools | |
| # 166K = 1MM/6, so that's the largest number under 1MM that could have identical # of digits | |
| for k in range (100000,166666): | |
| my_set = set() | |
| perms = itertools.permutations(str(k), len(str(k))) | |
| for i in perms: |
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
| # set up prime sieve to n- we'll need up to 999999 here, since we're investigating 6 figure combos | |
| total = 0 | |
| n=1000000 | |
| myPrimes = [True]*(n+1) | |
| mySum = [0]*(n+1) | |
| last = 0 | |
| for i in range (2,n): | |
| if myPrimes[i] == True: | |
| j = 2*i | |
| while j<=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
| # set up prime sieve to n- track running sum in separate sum array | |
| total = 0 | |
| n=1000000 | |
| myPrimes = [True]*(n+1) | |
| mySum = [0]*(n+1) | |
| last = 0 | |
| for i in range (2,n): | |
| if myPrimes[i] == True: | |
| j = 2*i | |
| while j<=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
| # http://projecteuler.net/problem=49 | |
| # we'll use the python built-in permutation function | |
| import itertools | |
| # prime sieve | |
| n=100000 | |
| myPrimes = [True]*(n+1) | |
| for i in range (2,n): | |
| if myPrimes[i] == True: |