[Python/2017] Move solutions into .py files

This commit is contained in:
Felix Bargfeldt 2023-10-29 13:29:25 +01:00
parent fbc5fda60f
commit 7b1efc0d9c
Signed by: Defelo
GPG key ID: 2A05272471204DD3
51 changed files with 1100 additions and 4546 deletions

35
Python/2017/15.py Normal file
View file

@ -0,0 +1,35 @@
from lib import *
input = read_input(2017, 15)
lines = input.splitlines()
def gen(prev, k):
return (prev * k) % 2147483647
a, b = [int(line.split()[-1]) for line in lines]
out = 0
M = 1 << 16
for _ in range(40000000):
a = gen(a, 16807)
b = gen(b, 48271)
out += a % M == b % M
print(out)
def generate(x, k, m):
while True:
x = gen(x, k)
if x % m == 0:
yield x
a, b = [int(line.split()[-1]) for line in lines]
out = 0
M = 1 << 16
for _, a, b in zip(range(5000000), generate(a, 16807, 4), generate(b, 48271, 8)):
out += a % M == b % M
print(out)