Skip to content

Instantly share code, notes, and snippets.

View igorvanloo's full-sized avatar

Igor igorvanloo

View GitHub Profile
@igorvanloo
igorvanloo / p59.py
Created July 25, 2021 14:08
Problem 59
def compute(cipher):
possiblecodes = []
for x in range(97,123):
for y in range(97, 123):
for z in range(97,123):
password = chr(x) + chr(y) + chr(z)
count = 0
decrypt = []
for i in cipher:
temp = i^(ord(password[count % 3]))
@igorvanloo
igorvanloo / p63.py
Created July 25, 2021 14:24
Problem 63
def compute():
count = []
for n in range(1,10):
for i in range(1,22):
if i == len(str(n**i)):
count.append(n**i)
return len(count)
#Used the following function to find the bounds for n
#n = 9 bound is 22 because 9^22
@igorvanloo
igorvanloo / p659.py
Created July 26, 2021 04:18
Problem 659
def compute(limit):
f = [int(4*(x**2)+1) for x in range(limit+1)] #Initialise the list f
max_prime_factor = [0]*(limit+1) #Initialise the list max_prime_factor
for x in range(1,len(f)): #Go through f
div = f[x] #Initialise divisor
if div > 1: #Check if divisor > 1
curr1 = x % div
while curr1 <= limit: #while curr = x + k*f[x] < limit we continue
if f[curr1] % div == 0: #Check if f[x+k*f[x]] is divisible by f[x]
max_prime_factor[curr1] = max(max_prime_factor[curr1], div)
@igorvanloo
igorvanloo / p700.py
Created July 26, 2021 12:55
Problem 700
def compute():
eulercoins = [1504170715041707]
current_eulercoin = 1504170715041707
inv = pow(1504170715041707, -1, 4503599627370517)
n = 2
while True:
number = 1504170715041707*n % 4503599627370517 #Search downwards
if number < current_eulercoin:
current_eulercoin = number
eulercoins.append(number)
@igorvanloo
igorvanloo / p743.py
Created July 27, 2021 13:52
Problem 743
def A(k,n):
total = 0
f0 = 1
modulo = 1000000007
power = pow(2, n//k, modulo)
for a in range(0, n//k + 1):
total = (total + (f0 * pow(power, k-2*a, modulo))) % modulo
f0 = (f0*(k-2*a)*(k-2*a-1)) % modulo
f0 = (f0*pow((a+1)**2, -1, modulo)) % modulo
return total
@igorvanloo
igorvanloo / p82.py
Last active July 28, 2021 09:49
Problem 82
def compute():
matrix = [[131, 673, 234, 103,18],
[201, 96, 342, 965, 150],
[630, 803, 746, 422, 111],
[537, 699, 497, 121, 956],
[805, 732, 524, 37, 331]]
rows = len(matrix) #Number of rows
columns = len(matrix[0])#Number of columns
@igorvanloo
igorvanloo / p618.py
Created July 28, 2021 18:29
Problem 618
def compute(limit):
d = [1] + [0] * limit
primes = eulerlib.primes(limit)
mod = 10**9
Fibonnaci_numbers = [2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368]
for p in primes:
for i in range(p,limit+1):
d[i] += (p*d[i-p] % mod)
@igorvanloo
igorvanloo / p61.py
Created July 29, 2021 10:25
Problem 61
def is_cyclic(x,y):
if (x % 100) == int(str(y // 100)):
return True
return False
def compute():
tri = [(int(x*(x + 1)/2), "triangle") for x in range(1,1000) if 999 < x*(x + 1)/2 < 10000]
sq = [(int(x*(x)), "square") for x in range(1,1000) if 999 < x*(x) < 10000]
pen = [(int(x*(3*x - 1)/2), "pentagonal") for x in range(1,1000) if 999 < x*(3*x - 1)/2 < 10000]
hexa = [(int(x*(2*x - 1)), "hexagonal") for x in range(1,1000) if 999 < (x*(2*x - 1)) < 10000]
@igorvanloo
igorvanloo / p78.py
Created July 29, 2021 13:39
Problem 78
def PentagonalNumberTheorem(N):
p = [1] + [0]*(N + 1) #Initalise array
for n in range(1,len(p)):
y = 1
while True:
if y % 2 == 0: #Find sign
sign = -1
else:
sign = 1
@igorvanloo
igorvanloo / p90.py
Created July 30, 2021 14:51
Problem 90
def dicecomb(): #Produces all dice combinations, there are 10 C 6 = 210
dicecombs = set()
for a in range(0,10):
for b in range(0,9):
for c in range(0,8):
for d in range(0,7):
for e in range(0,6):
for f in range(0,5):
if len(set([a,b,c,d,e,f])) == 6:
dicecombs.add(tuple(sorted((a,b,c,d,e,f))))