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): | |
v = [0]*(limit + 1) #v[k] = minimum number of multiplication to get n^k | |
count = 1 #Counting the number of solved k's. It's used to stop the while loop | |
stack = [(1,)] #The start stack, the only path of length 0 in the tree | |
currdepth = 1 #Keeping track of the current depth we are in the tree | |
while count != limit: | |
#We continue till we have found all 0 < k < 201 |
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_special_sum_set(A): | |
l = len(A) | |
#Generate all subsets and categorize them by length of set | |
#Then subsets[x] = all subsets of length x | |
subsets = [[] for x in range(l + 1)] | |
#Keep track of sums to test for duplicates (Condition 1) | |
sums = [] | |
#Here we generate all subsets while checking if condition 1 is satisfied |
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 gen_multiples(primes, multiplicities, limit): | |
if len(primes) == 0: | |
return [] | |
p = 1 | |
multiples = [] | |
for i in range(multiplicities[0] + 1): | |
if p > 1: | |
multiples.append(p) | |
if len(primes) > 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 segment(limit): | |
segmentstart = 0 | |
segmentsize = limit//1000 #adjust according to limit | |
b7max = [0]*(int(math.sqrt(limit)) + 1) #Keeps track of maximum b given a for each segment | |
b3max = [0]*(int(math.sqrt(limit)) + 1) | |
b2max = [0]*(int(math.sqrt(limit)) + 1) | |
b1max = [0]*(int(math.sqrt(limit)) + 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 gen_multiples(primes, pivalues, multiplicities, limit): | |
#Generates all multiples of given primes up to a cetain multiplicity | |
#Extra condition to precalculate pi(n) | |
p, vpi = 1, 1 | |
multiples = [] | |
for i in range(multiplicities[0] + 1): | |
if p > 1: | |
multiples.append((p, vpi)) | |
if len(primes) > 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
class SlidingGame: | |
def __init__(self, m, n): | |
self.board = self.create_board(m, n) | |
self.solution = self.find_best_path(self.board, m, n) | |
def create_board(self, m, n): | |
board = [] | |
for x in range(n): | |
board.append([1]*m) |
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(m, p): | |
line1 = '<p>Let $A$ be an <b>affine plane</b> over a <b>radically integral local field</b> $F$ with residual characteristic $p$.</p>' | |
line2 = '<p>We consider an <b>open oriented line section</b> $U$ of $A$ with normalized Haar measure $m$.</p>' | |
line3 = '<p>Define $f(m, p)$ as the maximal possible discriminant of the <b>jacobian</b> associated to the <b>orthogonal kernel embedding</b> of $U$ <span style="white-space:nowrap;">into $A$.</span></p>' | |
line4 = '<p>Find $f(20230401, 57)$. Give as your answer the concatenation of the first letters of each bolded word.</p>' | |
text = line1 + line2 + line3 + line4 | |
ans = "" | |
start = 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
import heapq | |
def widest(graph, start = 0, INFINITY = 10**10): | |
width = {} | |
cloud = {} | |
path = {} | |
for x in graph: | |
width[x] = INFINITY | |
cloud[x] = False | |
path[x] = (2,) #Optional, returns the actual path, useful for debugging |
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
is_prime = #A list such that is_prime[x] = True if x is prime | |
primes = #A list containing all the primes. Hint: generate it from is_prime | |
graph = {} | |
for k in range(len(primes)): | |
p = primes[k] | |
digits = [] | |
while p != 0: | |
digits.append(p % 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 genDuoDigits(d, x, y): | |
#This function generates all duodigits containing the numbers x and y up to d digits | |
duodigits = set() | |
combs = {0} | |
#We start with only the number 0 | |
for i in range(d): | |
temp = [] | |
#We will now generate all i + 1 digit duodigits | |
for v in combs: | |
#For every existing i digit duodigit we have, we can add x or y to the end of it to create an i + 1 digit duodigit |