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_…

Advent of Code: Day 9

For Day 9, the challenge is to parse a stream of text and counting occurences of certain patterns. Heres my Python solution: with open("input.txt", "r") as o: data = o.read() index = 0 current_score = 0 current_depth = 0 garbage_count = 0 def read(): global…

Advent of Code: Day 8

For Day 8, the challenge is to execute some simple instructions to manipulate registers, and then print some basic facts about the state of the registers. My Python solution is below: registers = {} highest_value = -99999 def check_condition(condition): register, command, value = condition.split(" ") value = int(value) if…