Skip to content

Commit

Permalink
Solution d8 part 1 python
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcolner committed Dec 12, 2023
1 parent c6ec632 commit 04e12e3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 2023/d8/python/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
with open("../input", "r") as t:
data = t.read()
lines = data.split("\n")
instructions = lines[0]
elements = {}
e = lines[2:]
e = e[:-1]
for v in e:
key = v.split(" = (")
k = key[1].split(", ")
elements[key[0]] = {"L": k[0].strip(), "R": k[1][:-1]}

answer = 1
cur_el = elements["AAA"]
instructions = instructions * 30000
print(instructions)
for c in instructions:
if cur_el[c] == "ZZZ":
break
else:
next_el = elements[cur_el[c]]
answer += 1
cur_el = next_el
print(answer)




9 changes: 9 additions & 0 deletions 2023/d8/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RL

AAA = (BBB, CCC)
BBB = (DDD, EEE)
CCC = (ZZZ, GGG)
DDD = (DDD, DDD)
EEE = (EEE, EEE)
GGG = (GGG, GGG)
ZZZ = (ZZZ, ZZZ)
5 changes: 5 additions & 0 deletions 2023/d8/test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LLR

AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)

0 comments on commit 04e12e3

Please sign in to comment.