Programming, Topic: Backtracking

Recent posts (Page 1 of 4)

Rescuing Gentoos with a Rust Solver (Part 2)

Rescuing Gentoos with a Rust Solver (Part 2)

And here we have Part 2! It’s not been that long for you, but since the first part took six months for me to actually get around to writing it… well, this is much better!

Things get a bit more complicated this time, with buttons that can open/close doors and even holes in the floor and BOMBS. But what’s really crazy is how we actually get around to solving how to get to new sublevels this time… and how to take penguins back out of them. Things are getting complicated!

Here are all of the commits from part 1 up through part 2.

And here are all of the parts in this series so far:

read more...

Rescuing Gentoos with a Rust Solver (Part 1)

Rescuing Gentoos with a Rust Solver (Part 1)

Months ago now1, I started playing Gentoo Rescue (after seeing the Aliensrock video). At the core, it’s a Sokoban style puzzle game where you have to guide cute little sliding penguins to their color coded nests… but oh man does it start getting more complicated quickly.

On top of that, it has a really interesting nesting level concept–the level select screens are levels themselves. You can go several ’levels’ deep into levels or eventually further back out. And that’s just with how far I’ve gotten so far…

read more...

AoC 2025 Day 12: Knapsackinator

Source: Day 12: Christmas Tree Farm

Full solution for today (spoilers!).

Part 1

Solve the knapsack problem.

But really, you are given a set of tiles (which all happen to be some subset of a 3x3) and a set of constraints–a MxN grid and how many of each tile to place. Count how many constraints are possible.

Tiles may be rotated and/or flipped.

read more...

Solving Woodworm

Solving Woodworm

Woodworm is a cute little PICO-8 puzzle game about a cute little worm… that eats wood. You can play it for free right now right here!

The goal is to turn this:

Level 1, before solving

Into this:

Level 1, after solving

There are a few rules to keep in mind:

  • The block (and the worm) are affected by gravity

  • The block can be split by into multiple pieces by eating it completely apart

    Demonstrating gravity

  • The worm can crawl up the side of blocks, so long as two (consecutive) segments of the worm are touching walls

    Demonstrating climbing

And that’s really it.

So let’s solve it!

read more...

Freshly (Frosted) Solved

Freshly (Frosted) Solved

And so it begins.

Freshly Frosted

It’s a cute little puzzle game about making a donut factory.

It’s a lot like Solving Cosmic Express in that it’s a ‘puzzle on rails’, you are basically routing around the grid from source to target. In the way, we have to go to certain tiles in a certain order (in this case, to apply toppings to our donuts).

The first level

Let’s do it!

read more...

AoC 2024 Day 17: Virtual Machininator

Source: Day 17: Chronospatial Computer

Full solution for today (spoilers!).

Part 1

Implement a virtual machine. The machine will have 3 unbounded signed registers, 8 opcodes (see below), a variable parameter scheme (see below that). You will be given the initial values of the 3 registers and a program. Find the final output.

Instructions

OpcodeInstructionDescriptionNotes
0adv reg/valA = A >> OP
1bxl valB = B ^ OP
2bst reg/valB = OP & 0b111
3jnz valIf a =/= 0, jump to LIT
4bxc ignoreB = B ^ CStill takes param, but ignores it
5out reg/valOutput bOnly outputs lowest 3 bits
6bdv reg/valB = A >> OPSame as adv but writes to b
7cdv reg/valC = A >> OPSame as adv but writes to c

Parameter specification

For instructions that can take reg/val, 0 to 3 (inclusive) are treated as literal values, 4 is register A, 5 is B, 6, is C, and 7 is an error (should never happen).

For instructions that only take val, it’s always a literal value in the range 0 to 7 (inclusive).

read more...

Solving Cosmic Express

Another Rust Solvers puzzle: Cosmic Express. Basically, it’s a routefinding puzzle. You have a train that needs a track from entrance to exit, picking up and dropping off cargo on the way.

It’s actual a relatively simple puzzle, so far as things go, but one thing that’s interesting from a solving perspective is that branching paths really don’t work great with my solver code. Paths just have a crazy branching factor when compared to (for example) playing one of a handful of cards.

But it’s still an interesting puzzle!

read more...


All posts