April 07, 2024

Solution for Advent of Code 2016 - Day 13: A Maze of Twisty Little Cubicles

Link to the puzzle text

Part 1

In this puzzle we should navigate a maze from start to a specific point. If a cell contains a wall depends on the x / y coordinates and our puzzle input.

def valid_move(x, y):
number = x * x + 3 * x + 2 * x * y + y + y * y + INPUT
bit_string = bin(number)
number_ones = bit_string.count("1")
if number_ones % 2 == 0:
return True
else:
return False

The rest can be done with a simple A* search. We include the manhattan distance as a heuristic and keep a list of previously visited cells to speed up the search.

Part 2

In part 2, the task is not to find the shortest distance to a cell, but to count the number of cells reachable in 50 steps instead.

We keep most of the code from part 1, but remove the end state check. Instead paths longer than 50 steps are cut off. At the end, we return the list of visited cells.

Link to my solutions

No comments:

Post a Comment