This commit is contained in:
dece 2020-12-27 15:19:58 +01:00
parent 595db92c73
commit 2a07c6458c

29
2020/day25.py Normal file
View file

@ -0,0 +1,29 @@
import sys
def main():
lines = [line.rstrip() for line in sys.stdin]
cpk, dpk = int(lines[0]), int(lines[1])
dls = crack(dpk, 7) # cracking door's key is much quicker
k = gen_key(cpk, dls)
print(k)
def step(v, sn):
return (v * sn) % 20201227
def crack(pk, sn):
i = 0
v = 1
while v != pk:
v = step(v, sn)
i += 1
return i
def gen_key(sn, ls):
v = 1
for _ in range(ls):
v = step(v, sn)
return v
if __name__ == "__main__":
main()