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
| 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(): |
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 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: |
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] |