Skip to content

Instantly share code, notes, and snippets.

@hatashiro
hatashiro / projecteuler3.py
Created April 13, 2012 12:17
Projecteuler #3
def primefactor(int):
div = 2
obj = int
while True:
if obj % div:
div = div + 1
else:
obj = obj / div
if obj == 1:
return div
@hatashiro
hatashiro / projecteuler4.py
Created April 13, 2012 14:09
Projecteuler #4
def isPalindrome(int):
intstr = str(int)
length = len(intstr)
if length%2:
mid = length / 2
pre = intstr[0:mid]
suf = intstr[mid+1:length]
else:
mid = length / 2
pre = intstr[0:mid]
@hatashiro
hatashiro / projecteuler5.py
Created April 13, 2012 14:44
Projecteuler #5
def lcd(a, b):
if a==1 or b==1:
return a*b
a_now = a
b_now = b
denominator = 1
factor = 2
while True:
if a_now%factor and b_now%factor:
factor = factor + 1
@hatashiro
hatashiro / projecteuler6.py
Created April 13, 2012 15:20
Projecteuler #6
def sum_of_square_from_1_to(int):
return sum([i**2 for i in range(1, int+1)])
def square_of_sum_from_1_to(int):
return sum(range(1, int+1))**2
def result(int):
return square_of_sum_from_1_to(int) - sum_of_square_from_1_to(int)
@hatashiro
hatashiro / projecteuler7.py
Created April 14, 2012 13:10
Projecteuler #7
import math
def isPrime(num):
if num == 1:
return False
div = 2
obj = num
sqrt = int(math.sqrt(num))
while True:
if div > sqrt:
@hatashiro
hatashiro / projecteuler8.py
Created April 16, 2012 06:09
Projecteuler #8
num = 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
numstr = str(num
@hatashiro
hatashiro / projecteuler9.py
Created April 18, 2012 07:46
Projecteuler #9
def isPythagorean(a, b, c):
return a**2 + b**2 == c**2
a = 1
b = 500
while True:
if isPythagorean(a, b, 1000-a-b):
break
else:
b = b+1
@hatashiro
hatashiro / projecteuler10.py
Created April 18, 2012 07:52
Projecteuler #10
import math
def isPrime(num):
if num == 1:
return False
div = 2
obj = num
sqrt = int(math.sqrt(num))
while True:
if div > sqrt:
@hatashiro
hatashiro / projecteuler11.py
Created April 18, 2012 09:20
Projecteuler #11
a = """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
@hatashiro
hatashiro / projecteuler12.py
Created April 19, 2012 07:46
Projecteuler #12
import math
def numDivisor(integer):
i = 1
num = 0
limit = int(math.sqrt(integer))
while True:
if not integer%i:
num = num + 1
i = i + 1