Advent of Code: Day 19

For Day 19, the challenge is to follow a map, recording letters that are passed on the route. import time UP = (0, -1) DOWN = (0, 1) LEFT = (-1, 0) RIGHT = (1, 0) with open("input.txt", "r") as o: m = o.readlines() y = 0 x = m[…

Advent of Code: Day 18

For Day 18, we have another challenge that involves implementing a parser. My Python solution is: import time import Queue from itertools import cycle with open("input.txt", "r") as o: commands = o.read().split("\n") class Program(): def __init__(self, id, commands, in_…

Advent of Code: Day 17

For Day 17, the challenge is to repeatedly insert numbers into a list following some specific rules, and then find the position of a given number. My Python solution is below: with open("input.txt", "r") as o: steps = int(o.read()) def spinlock(max_number,…

Advent of Code: Day 16

For Day 16, the challenge is to rearrange characters according to a given "dance" a billion times and find where they end up. My Python solution is below: import string with open("input.txt", "r") as o: commands = o.read().split(",") order…

Advent of Code: Day 15

For Day 15, the challenge is to create some generators which follow particular rules for generating sequences, and then count the number of times the results match. My Python solution is below: with open("input.txt", "r") as o: seed1 = int(o.readline().rsplit(" "…

Advent of Code: Day 14

For Day 14, the challenge is to generate a sort of map by generating hashes, and then count the number of contiguous regions in that map. My Python solution is: import Queue from day10 import hash with open("input.txt", "r") as o: key = o.read(…

Advent of Code: Day 13

For Day 13, the challenge is to figure out a safe path through some moving "scanners". My Python solution is below: import itertools layers = {} max_depth = 0 with open("input.txt", "r") as o: for line in o.readlines(): depth, r = line.strip().split(…

Advent of Code: Day 12

For Day 12, the challenge is to count the number of isolated groups within a graph. My Python solution is below: connections = {} with open("input.txt", "r") as o: for line in o.read().split("\n"): p = line.split(" <-> "…

Advent of Code: Day 11

For Day 11, the challenge is to optimize a path through a hex grid. My Python solution is below: with open("input.txt", "r") as o: directions = o.read().split(",") DIR = { "n": (0, 1, -1), "nw": (-1, 1, 0), "…

Advent of Code: Day 10

For Day 10, the challenge is to hash a string using a "knot-based" hash algorithm. My Python solution is below: from functools import reduce class CircularList(list): def __getitem__(self, x): return super(CircularList, self).__getitem__(x % len(self)) def __setitem__(self, x, v): super(CircularList, self).__setitem_…