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 winnings(x, f): | |
| return pow(1 + 2*f, x) * pow(1 - f, 1000 - x) | |
| def find_f(): | |
| #Finds the optimal f | |
| f = 0.001 | |
| goal = 10**9 | |
| step = 0.001 #Adjust this for greater accuracy | |
| best_f, corresponding_x = 0, 1000 | |
| while f < 0.5: |
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
| from prime_sieve.array import PrimeArraySieve | |
| def prime_factors_with_exponent(n): | |
| factors = [] | |
| d = 2 | |
| while n > 1: | |
| count = 0 | |
| while n % d == 0: | |
| count += 1 | |
| n /= d |
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 |