From 1010cacbe963dcd885e3ab70fc0a6c4fe36cb77d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 29 Dec 2024 23:50:09 -0500 Subject: [PATCH] 2018: d14: ex2: add solution --- 2018/d14/ex2/ex2.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 2018/d14/ex2/ex2.py diff --git a/2018/d14/ex2/ex2.py b/2018/d14/ex2/ex2.py new file mode 100755 index 0000000..844c250 --- /dev/null +++ b/2018/d14/ex2/ex2.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import sys + + +def solve(input: str) -> int: + digits = [int(n) for n in input.strip()] + + scores = [3, 7] + elves = [0, 1] + + while scores[-len(digits) :] != digits and scores[-len(digits) - 1 : -1] != digits: + sum = scores[elves[0]] + scores[elves[1]] + scores.extend(map(int, str(sum))) + elves = [(elf + 1 + scores[elf]) % len(scores) for elf in elves] + + left_of_digits = len(scores) - len(digits) - (scores[-len(digits) :] != digits) + return left_of_digits + + +def main() -> None: + input = sys.stdin.read() + print(solve(input)) + + +if __name__ == "__main__": + main()