Our great sponsors
-
AdventOfCode2021
Solutions to all 25 AoC 2021 problems in Rust :crab: Less than 100 lines per day and under 1 second total execution time! :christmas_tree:
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
You can see it written in Rust here: https://github.com/Mahrgell/AoC2021/blob/main/aoc21-24/src/main.rs
Since you are only interested in the highest (or lowest) result a depth-first search should be faster. Haven't benchmarked anything nor was that my own idea (i took https://github.com/AxlLind/AdventOfCode2021/blob/main/src/bin/24.rs as a starting point, when my basic ALU was working) i'm just curious how other people solve the problems.
I used the Z3 Theorem Prover. First, I construct the constraints from the input. The inputs are 14 free integer variables between 1 and 9, and then I apply all the operations and add a constraint that z must be 0. Then I use the optimizer to maximize/minimize for the model number.
Code for those who are curious.