Advent of Haskell: Day 1

I recently completed Advent of Code 2017, and enjoyed it so much I'm going to go back to do the previous years. I ended up doing almost all of this year's in Python as that's my most comfortable language for hacking things out, so I didn't really use this year's…

Advent of Code: Day 25

For Day 25, the challenge is to implement a turing machine simulator. My Python solution is: states = {} current_state = None current_rule = None def enter_state(line): global current_state current_state = line.rsplit(" ", 1)[-1][:-1] if current_state not in states: states[current_state] = {} def enter_…

Advent of Code: Day 23

For Day 23, the challenge is to understand what some assembly code is doing and calculate the answer. This is probably my favourite challenge so far. My initial interpreter is: import time import Queue from itertools import cycle with open("input.txt", "r") as o: commands…

Advent of Code: Day 22

For Day 22, the challenge is to follow some rules to spread a virus through an infinite grid. import copy marked = {} UP = (0, -1) DOWN = (0, 1) LEFT = (-1, 0) RIGHT = (1, 0) CLEAN = 0 WEAKENED = 1 INFECTED = 2 FLAGGED = 3 def turn(current, turn_direction): if current == UP: return…

Advent of Code: Day 21

For Day 21, the challenge is to follow a set of rules to convert some strings. import numpy as np rules = {} def flipandrotate(base): np_base = np.array(list(list(x) for x in base.split("/"))) flipped = np.fliplr(np_base) res = [] for i in range(4): for…

Advent of Code: Day 20

For Day 20, the challenge is to simulate some particles, removing those that collide. import re import copy STABLE = 500 class Particle: def __init__(self, id, p, v, a): self.id = id self.p = p self.v = v self.a = a self.collided = False def tick(self): self.v[0]…

Advent of Code: Day 24

For Day 24, the challenge is to calculate the optimal combination of pieces to build a bridge of sufficient distance and strength. My brute force solution in Python is: paths = {} with open("input.txt", "r") as o: for line in o: parts = line.strip().split("…

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