Skip to content

Instantly share code, notes, and snippets.

View igorvanloo's full-sized avatar

Igor igorvanloo

View GitHub Profile
@igorvanloo
igorvanloo / pe136.py
Last active December 3, 2021 12:47
pe136
def compute(limit): #set limit to 5*10**6
array = [0]*(limit)
for a in range(1, limit):
for d in range(int(math.floor(a/4))+1, a):
n = a*(4*d-a)
if n > limit-1:
break
else:
array[n] += 1
return array.count(1)
@igorvanloo
igorvanloo / p110.py
Last active August 1, 2021 14:16
Problem 110
def compute(): #Ugliest code known to man
minimum = 614889782588491410
for e1 in range(1,60):
print("e1", e1)
divisors = (2*e1 + 1)
number = 2**e1
for e2 in range(1, 23):
divisors = (2*e1 + 1)*(2*e2 + 1)
number = 2**e1 * 3**e2
if number > minimum:
@igorvanloo
igorvanloo / p107.py
Created July 31, 2021 17:39
Problem 107
def PrimsAlgorithm(graph):
#Find dimension of graph, as well as previous weight
dimension = len(graph)
Previous_Weight = sum([graph[x][y] for x in range(dimension) for y in range(x+1, dimension) if graph[x][y] != 0])
Tree = set([0]) #Step 1
New_Weight = 0
for x in range(dimension - 1):
Minimum_edge, Corresponding_vertex = min([(graph[x][y], y) for x in Tree \
@igorvanloo
igorvanloo / p101.py
Created July 31, 2021 17:26
Problem 101
def PolynomialInterpolator(sequence):
if len(sequence) == 1: #Basic case
return sequence[0][1]
elif len(sequence) == 2: #Still basic
return sequence[1][1] + (sequence[1][1] - sequence[0][1])
else: #Using Lagrange's Formula
length = len(sequence)
goal = length + 1
total = 0
for x in range(length):
@igorvanloo
igorvanloo / p98.py
Created July 31, 2021 13:02
Problem 98
def wordchecker(word, number):
word_fingerprint = []
for x in word:
word_fingerprint.append(word.count(x))
number_fingerprint = []
for x in number:
number_fingerprint.append(number.count(x))
if word_fingerprint == number_fingerprint:
@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))))
@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 / 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 / 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 / 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