aboutsummaryrefslogtreecommitdiffstats
path: root/src/14
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2020-12-08 21:53:34 +0100
committerLouis Burda <quent.burda@gmail.com>2020-12-08 21:53:34 +0100
commit61c19fd58a9c32919b9b06d38dd9ba202cf43bfb (patch)
tree716d58ee8979d3df123acfedcd5cb8472722d422 /src/14
downloadaoc2018-python-61c19fd58a9c32919b9b06d38dd9ba202cf43bfb.tar.gz
aoc2018-python-61c19fd58a9c32919b9b06d38dd9ba202cf43bfb.zip
Solve 25 days
Diffstat (limited to 'src/14')
-rw-r--r--src/14/input.txt1
-rw-r--r--src/14/solve.py42
2 files changed, 43 insertions, 0 deletions
diff --git a/src/14/input.txt b/src/14/input.txt
new file mode 100644
index 0000000..1c93252
--- /dev/null
+++ b/src/14/input.txt
@@ -0,0 +1 @@
+110201
diff --git a/src/14/solve.py b/src/14/solve.py
new file mode 100644
index 0000000..fd6488c
--- /dev/null
+++ b/src/14/solve.py
@@ -0,0 +1,42 @@
+from sys import argv as args
+
+inputstr = open("input.txt").read().replace("\n","")
+recipes = [3,7]
+
+def solve1():
+ global recipes, inputstr
+
+ end = int(inputstr)
+ 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)
+ print("".join([str(x) for x in recipes[end:]]))
+
+def solve2():
+ global recipes, inputstr
+
+ ilen = len(inputstr)
+ inputstr = [int(c) for c in inputstr]
+ 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:] == inputstr:
+ stop = True
+ break
+ recipes.append(v)
+ for i in range(len(workers)):
+ workers[i] = (workers[i] + recipes[workers[i]]+1) % len(recipes)
+ print(len(recipes)-ilen)
+
+def main():
+ if len(args) > 1:
+ if args[1] == "1":
+ solve1()
+ elif args[1] == "2":
+ solve2()
+
+main()