December 11, 2023

Solution for Advent of Code 2015 - Day 21: RPG Simulator 20XX

Link to the puzzle text

Part 1

For this part, we need to simulate an RPG fight. The stats of the player character are influenced by items bought and we are asked to find to cheapest combination of items to defeat an enemy.

This is again best solved by a brute-force search over all item combinations. For each we simulate the fight and update the cheapest value if the player wins and the items are cheaper. The fight itself is an endless loop where the player and the enemy consecutively attack and reduce the other ones hit points.

Part 2

In part 2, we are trying to find the most expensive item combination to still lose. The search algorithm from part 1 was reused and we just update if the player loses a fight and the items are more expensive than before.

Link to my solutions

No comments:

Post a Comment