Solve three easy problems to Easy Prey award.
parent
18180491c2
commit
5df0bcb2ac
|
@ -0,0 +1,28 @@
|
|||
def remainder(a: int, n: int) -> int:
|
||||
d = a * a
|
||||
return (pow(a - 1, n, d) + pow(a + 1, n, d)) % d
|
||||
|
||||
|
||||
def max_remainder(a: int) -> int:
|
||||
n, r_max = 1, 2
|
||||
while True:
|
||||
r = remainder(a, n)
|
||||
if r == r_max:
|
||||
break
|
||||
if r > r_max:
|
||||
r_max = r
|
||||
n += 1
|
||||
assert(r_max > 2)
|
||||
return r_max
|
||||
|
||||
|
||||
def euler_120():
|
||||
assert(remainder(7, 3) == 42)
|
||||
assert(max_remainder(7) == 42)
|
||||
return sum([max_remainder(n) for n in range(3, 1001)])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = euler_120()
|
||||
print("e120.py: " + str(solution))
|
||||
assert(solution == 333082500)
|
|
@ -0,0 +1,69 @@
|
|||
from typing import List, Optional
|
||||
from math import sqrt
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
def to_int(digits: List[int]) -> int:
|
||||
return int("".join(map(str, digits)))
|
||||
|
||||
|
||||
def int_len(n: int) -> int:
|
||||
return len(str(n))
|
||||
|
||||
|
||||
@lru_cache
|
||||
def digits_make_sum(digits, remainder: int) -> Optional[List]:
|
||||
if len(digits) == 0:
|
||||
if remainder == 0:
|
||||
return []
|
||||
return None
|
||||
|
||||
remainder_digits_count = int_len(remainder)
|
||||
if remainder_digits_count > len(digits):
|
||||
return None
|
||||
|
||||
if to_int(digits) < remainder:
|
||||
return None
|
||||
|
||||
for group_size in range(1, remainder_digits_count + 1):
|
||||
digits_list = list(digits)
|
||||
rest_value = remainder - to_int(digits_list[:group_size])
|
||||
rest_digits = tuple(digits_list[group_size:])
|
||||
r = digits_make_sum(rest_digits, rest_value)
|
||||
if type(r) is list:
|
||||
return [digits_list[:group_size]] + r
|
||||
return None
|
||||
|
||||
|
||||
def digits_sum_to(digits, number: int):
|
||||
r = digits_make_sum(digits, number)
|
||||
if type(r) is list:
|
||||
# print(digits, r, number)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def t(limit: int) -> int:
|
||||
r = 0
|
||||
for base in range(4, int(sqrt(limit)) + 1):
|
||||
n = base * base
|
||||
n_digits = tuple(map(int, list(str(n))))
|
||||
if digits_sum_to(n_digits, base):
|
||||
r += n
|
||||
return r
|
||||
|
||||
|
||||
def euler_719():
|
||||
assert(t(10**4) == 41333)
|
||||
assert(digits_sum_to((1, 0, 0), 10) == True)
|
||||
assert(digits_sum_to((1, 8), 9) == True)
|
||||
assert(digits_sum_to((2, 5), 5) == False)
|
||||
assert(digits_sum_to((8, 2, 8, 1), 91) == True)
|
||||
assert(t(10**6) == 10804656)
|
||||
return t(10**12)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = euler_719()
|
||||
print("e719.py: " + str(solution))
|
||||
assert(solution == 128088830547982)
|
|
@ -0,0 +1,27 @@
|
|||
import re
|
||||
|
||||
|
||||
TEXT = """
|
||||
<p>Let $A$ be an <b>affine plane</b> over a <b>radically integral local field</b> $F$ with residual characteristic $p$.</p>
|
||||
|
||||
<p>We consider an <b>open oriented line section</b> $U$ of $A$ with normalized Haar measure $m$.</p>
|
||||
|
||||
<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>
|
||||
|
||||
<p>Find $f(20230401, 57)$. Give as your answer the concatenation of the first letters of each bolded word.</p>
|
||||
"""
|
||||
|
||||
|
||||
def euler_836():
|
||||
r = ''
|
||||
for m in re.findall(r'<b>(.*?)</b>', TEXT):
|
||||
words = m.split(' ')
|
||||
for word in words:
|
||||
r += word[0]
|
||||
return r
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = euler_836()
|
||||
print("e836.py: " + str(solution))
|
||||
assert(solution == 'aprilfoolsjoke')
|
Loading…
Reference in New Issue