From 61835097037f74aaff183f97e74d6957bf00a703 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 25 Dec 2020 11:39:46 +0100 Subject: [PATCH] 2020: d25: ex1: add solution --- 2020/d25/ex1/ex1.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 2020/d25/ex1/ex1.py diff --git a/2020/d25/ex1/ex1.py b/2020/d25/ex1/ex1.py new file mode 100755 index 0000000..6e346d5 --- /dev/null +++ b/2020/d25/ex1/ex1.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import itertools +import sys +from typing import List + + +def step(value: int, subject: int) -> int: + value *= subject + value %= 20201227 + return value + + +def solve(raw: List[int]) -> int: + value = 1 + + for rounds in itertools.count(1): + value = step(value, 7) + if value == raw[0]: + break + + key = 1 + for __ in range(rounds): + key = step(key, raw[1]) + + return key + + +def main() -> None: + input = [int(line) for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main()