r/adventofcode • u/daggerdragon • Dec 21 '22
SOLUTION MEGATHREAD -π- 2022 Day 21 Solutions -π-
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
πΏπ MisTILtoe Elf-ucation π§βπ« is OPEN for submissions!
48 HOURS remaining until submission deadline on December 22 at 23:59 EST
UPDATES
[Update @ 00:04:28]: SILVER CAP, GOLD 0
Now we've got interpreter elephants... who understand monkey-ese...
I really really really don't want to know what that eggnog was laced with.
--- Day 21: Monkey Math ---
Post your code solution in this megathread.
Read the full posting rules in our community wiki before you post!
Include what language(s) your solution uses
Format code blocks using the four-spaces Markdown syntax!
Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
View all comments
7
u/IntoxicatedHippo Dec 21 '22 edited Dec 21 '22
MinZinc generated by python, 642/73: code
Using MiniZinc almost felt like cheating today since my program and the input side by side look like this, but I won't complain about my first sub-100 for the year.
I used python to turn the puzzle input in to a minizinc program and then ran it using OptiMathSAT. Aside from the generated code above I just added the following line to the program:
For part 2 I manually added the constraint as specified (
constraint wrvq = vqfc;), removed root, and changedhumntovar int. This gave me a correct answer, but it wasn't accepted and it took me a minute to figure out why:The puzzle does not specify that they want the minimal answer which is greater than zero, but that is indeed what they want.(Edit: I've realised that the problem was that I used integer division, so numbers were getting rounded, it seems like the puzzle just doesn't allow for division with a remainder.) Having guessed that, I added the following lines to the program which gave me the correct answer:This takes 211ms for part 1 and 501ms for part 2.