Skip to content

Instantly share code, notes, and snippets.

View igorvanloo's full-sized avatar

Igor igorvanloo

View GitHub Profile
@igorvanloo
igorvanloo / p491.py
Created December 9, 2021 05:56
p491
import itertools
def number_of_doubles(pand):
doubles = 0
for x in range(0,10):
if pand.count(str(x)) == 2:
doubles += 1
return doubles
def compute():
@igorvanloo
igorvanloo / p150.py
Created December 6, 2021 10:19
p150
def triangle_generator():
t = 0
s = []
for k in range(1,500501):
t = (615949*t + 797807) % 2**20
s.append(t - 2**19)
#First I generate the s values
triangle = []
r = 1000
while r != 0:
@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]