December 16, 2023

Solution for Advent of Code 2015 - Day 22: Wizard Simulator 20XX

Link to the puzzle text

Part 1

Similar to last day, we need to simulate an fight. This time the player controls a wizard and needs to select the correct spells each turn to defeat an enemy. The task is to minimize the mana costs of these spells while still winning the fight.

A simple search without heuristics for the spell sequence was enough to solve this problem. We keep a queue sorted by the current mana cost containing the used spells. At each step, if the fight until now is simulated. If we defeat the enemy, we found the minimal solution. If we are defeated, we stop searching in this branch. In the most likely scenario, we run of out spells defined. In this case, we add all possible spells to the queue with their respective mana costs.

The fight simulation was the most complex part of this puzzle, since their are effects ranging over multiple rounds.

Part 2

In part 2, the fight is made more complicated by the player losing 1 hp per round.

This was incorporated into the fight simulator and the search was run again. It only took a bit more time, but the solution was found again.

Link to my solutions

No comments:

Post a Comment