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
amicable = {} | |
d = [0 for x in xrange(10000)] | |
def getSumOfDivisors(n): | |
divisors = [1] | |
i = 2 | |
while n / i > i: | |
if n % i == 0: | |
divisors.append(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
a = [] | |
def getTriangleFromFile(): | |
f = open("triangle.txt") | |
for line in f: | |
b = [int(x) for x in line.split()] | |
a.append(b) | |
maxPaths = dict() |
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
singleDigits = ["zero","one","two","three","four","five","six","seven","eight","nine"] | |
tens = ["zero","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"] | |
teens = ["zero"] * 11 + ["eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"] | |
hundredLength = len("hundred") | |
andLength = len("and") | |
singleDigits = [len(x) for x in singleDigits] |
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
a = str(2 ** 1000) | |
print reduce(lambda x, y : int(x) + int(y), a) |
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
short = dict() | |
def getPaths(x, y): | |
if x == 0 and y == 0: | |
return 0 | |
if x == 0: | |
return 1 | |
if y == 0: | |
return 1 | |
if (x,y) in short: |
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
a = [ | |
[8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8], | |
[49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,4,56,62,0], | |
[81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,3,49,13,36,65], | |
[52,70,95,23,4,60,11,42,69,24,68,56,1,32,56,71,37,2,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,3,45,2,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,2,62,12,20,95,63,94,39,63,8,40,91,66,49,94,21], | |
[24,55,58,5,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72], |
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
#We take the opposite approach here and find all the composite numbers | |
# upto 2 million and then we sum what is not composite(prime). | |
def prime(n): | |
composite = range(n) | |
for a in xrange(2, n): | |
b = a | |
for b in xrange(a * a, n, a): | |
composite[b] = 0; | |
sum = 0 |
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
def special(): | |
for a in xrange(1, 1001): | |
for b in xrange(1, 1001): | |
c = 1000 -a -b; | |
if c < 0: | |
break; | |
if a * a + b * b == c * c: | |
return a*b*c | |
print special() |
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
def largest_product(number): | |
maxProduct = 1 | |
for i in range(len(number) - 5): | |
product = reduce(lambda x,y : int(x) * int (y), number[i: i + 5]) | |
if product > maxProduct: | |
maxProduct = product | |
return maxProduct | |
a = \ | |
'73167176531330624919225119674426574742355349194934' +\ |
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
def prime(n): | |
primes = [2] | |
start = 3 | |
while len(primes) <= n: | |
isPrime = True; | |
for prime in primes: | |
if start % prime == 0: | |
isPrime = False; | |
break; | |
if isPrime: |
NewerOlder