This file contains hidden or 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 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) |
This file contains hidden or 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 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: |
This file contains hidden or 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 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 \ |
This file contains hidden or 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 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): |
This file contains hidden or 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 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: |
This file contains hidden or 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 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)))) |
This file contains hidden or 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 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 |
This file contains hidden or 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 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] |
This file contains hidden or 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 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) | |
This file contains hidden or 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 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 | |