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 u(k, r): | |
return (900 - 3*k)*pow(r, k-1) | |
def s(n, r): | |
total = 0 | |
for k in range(1, n+1): | |
total += u(k, r) | |
return total | |
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 legendre_factorial(x): | |
primes = list_primes(a) | |
prime_fac = {} | |
for y in primes: | |
total = 0 | |
for i in range(1, int(math.floor(math.log(x, y))) + 1): | |
total += int(math.floor(x / (y ** i))) | |
prime_fac[y] = total | |
return prime_fac |
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 math | |
from scipy.integrate import quad | |
def f(x): | |
return (1 - math.sqrt(2*x - 4*x*x))/2 | |
def I(x): | |
if x == 1: | |
return 1/2 | |
if 0 < x <= 1/2: |
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 Divisors_of(x): # Find the divisors of a number | |
divisors = [] | |
for i in range(1, int(math.sqrt(x)) + 1): | |
if x % i == 0: | |
divisors.append(i) | |
return (divisors) | |
def compute(): | |
alexandrian_integers = [] | |
p = 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 fermat_primality_test(n): | |
if pow(4, n - 1, n) == 1 and pow(6, n - 1, n) == 1: | |
return True | |
return False | |
def prime_proof_checker(x): | |
og = list(str(x)) | |
number = list(str(x)) | |
prime_proof = True | |
for pos in range(len(number)): |
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 f(x): | |
return math.floor(pow(2, 30.403243784 - x*x)) * pow(10, -9) | |
def compute(): | |
u_0 = -1 | |
prev_sum = 0 | |
running = True | |
while running: | |
u_n = f(u_0) | |
u_prev = u_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 valid(n): | |
if n < 0 or n > 9: | |
return False | |
return True | |
def compute(): | |
total = 0 | |
for a in range(0, 10): | |
print(a) | |
for b in range(0, 10): |
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): | |
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]) | |
New_Weight = 0 | |
for x in range(dimension - 1): | |
Minimum_edge, Corresponding_vertex = min([(graph[x][y], y) for x in Tree for y in \ | |
range(dimension) if y not in Tree and graph[x][y] != 0]) | |
Tree.add(Corresponding_vertex) | |
New_Weight += Minimum_edge |
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 DijkstrasAlgorithm(graph, start_node = 0, INFINITY = 10**10): | |
#Takes a weighted adjacency list as input of the graph | |
n = len(graph) | |
D = [INFINITY]*n | |
D[start_node] = 0 | |
cloud = [False for i in range(n)] | |
for i in range(n): | |
_, v = min((D[i], i) for i in range(n) if cloud[i] == False) | |
cloud[v] = True |
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 legendre_symbol(a, p): | |
t = pow(a, (p-1)//2, p) | |
if t == p - 1: | |
return -1 | |
return t | |
def tonelli_shanks(a, p): | |
if legendre_symbol(a, p) != 1: | |
return 0 | |
elif a == 0: |