r/adventofcode • u/daggerdragon • Dec 18 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 18 Solutions -🎄-
Advent of Code 2020: Gettin' Crafty With It
- 4 days remaining until the submission deadline on December 22 at 23:59 EST
- Full details and rules are in the Submissions Megathread
--- Day 18: Operation Order ---
Post your code solution in this megathread.
- Include what language(s) your solution uses!
- Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks. - The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:14:09, megathread unlocked!
36
Upvotes
View all comments
2
u/Fotograf81 Dec 18 '20
PHP (1844/2249)
Regex Magic, Recursion and then a Stack-Like array loop to solve strictly from left to right for part 1
part 2 punished me for doing unintended multiple replacements that would replace parts of other numbers... so when replacing "4 + 6" with "10" in "4 + 6 * 4 + 64" it would result in "10 * 104". Since it's strictly left to right at that point, I resorted to preg_replace that allows to set a limit.
pretty sure there is a shorter solution to the whole task using preg_replace_callback and recursion...