import sys sys.path.append("../common") import aoc data = aoc.data recipes = [3, 7] def solve1(args): global recipes, data end = int(data) workers = [i for i in range(2)] while len(recipes) < end + 10: recipes += [int(c) for c in str(sum(recipes[workers[i]] for i in range(len(workers))))] for i in range(len(workers)): workers[i] = (workers[i] + recipes[workers[i]]+1) % len(recipes) return "".join([str(x) for x in recipes[end:]]) def solve2(args): global recipes, data ilen = len(data) data = [int(c) for c in data] workers = [i for i in range(2)] stop = False counter = 0 while not stop: for v in [int(c) for c in str(sum(recipes[workers[i]] for i in range(len(workers))))]: if recipes[-ilen:] == data: stop = True break recipes.append(v) for i in range(len(workers)): workers[i] = (workers[i] + recipes[workers[i]]+1) % len(recipes) return len(recipes) - ilen aoc.run(solve1, solve2, sols=["6107101544", 20291131])