From a7eac8ea74a720dfa74673563e6b8a63b8c9f523 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 29 Dec 2024 23:49:51 -0500 Subject: [PATCH] 2018: d14: ex1: add solution --- 2018/d14/ex1/ex1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 2018/d14/ex1/ex1.py diff --git a/2018/d14/ex1/ex1.py b/2018/d14/ex1/ex1.py new file mode 100755 index 0000000..1f25cb8 --- /dev/null +++ b/2018/d14/ex1/ex1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import functools +import sys + + +def solve(input: str) -> int: + n_recipes = int(input) + + scores = [3, 7] + elves = [0, 1] + + while (len(scores) - 10) < n_recipes: + sum = scores[elves[0]] + scores[elves[1]] + scores.extend(map(int, str(sum))) + elves = [(elf + 1 + scores[elf]) % len(scores) for elf in elves] + + return functools.reduce(lambda lhs, rhs: lhs * 10 + rhs, scores[-10:]) + + +def main() -> None: + input = sys.stdin.read() + print(solve(input)) + + +if __name__ == "__main__": + main()