Day 25
This commit is contained in:
parent
595db92c73
commit
2a07c6458c
29
2020/day25.py
Normal file
29
2020/day25.py
Normal 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()
|
Loading…
Reference in a new issue