Advent of Code 2026 day 2
collections is showing again that it is well worth learning. pos is
probably unnecessary and could have gotten away with just distance and
modulo, but heyho.
with open("2.txt") as f:
instructions = f.read().strip()
colours = "roygbv"
pos = 0
distance = 0
for i in instructions:
if pos == colours.find(i):
distance += len(colours)
else:
distance += (colours.find(i) - pos) % len(colours)
pos = colours.find(i)
print(distance)
from collections import Counter
c = Counter(instructions)
print(
(c["r"])*6 +
5 + (c["v"]-1)*6 +
5 + (c["b"]-1)*6 +
5 + (c["g"]-1)*6 +
5 + (c["y"]-1)*6 +
5 + (c["o"]-1)*6
)