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 |
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 xorProduct(x, y): | |
prod = 0 | |
#Note that 0 ^ x = x, ^ = XOR | |
while y != 0: | |
if y % 2 == 1: | |
#If the first bit of y is a 1, prod = prod ^ x | |
prod ^= x | |
#Then we shift x one bit to the left, essentially adds a 0 behind x | |
x <<= 1 | |
#And we push y one bit to the right, essentially removes the first bit |
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 | |
from functools import lru_cache | |
@lru_cache(maxsize = 10**5) | |
def recursiveGenerate(A): | |
values = set() | |
#If our subset has a single element, then that element is the only constructable number | |
if len(A) == 1: | |
values.add(A[0]) |