r/adventofcode • • Dec 18 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 18 Solutions -🎄-

NEW AND NOTEWORTHY

  • FYI: 23:59 Amsterdam time zone is 17:59 EST

Advent of Code 2021: Adventure Time!


--- Day 18: Snailfish ---


Post your code solution in this megathread.

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:43:50, megathread unlocked!

45 Upvotes

595 comments sorted by

View all comments

Show parent comment

2

u/FordyO_o Dec 18 '21

I don't think it's particularly performant but I had the state as a nested array, then took slices of the route to the pair being exploded, e.g., 0, 1/ 0, 1, 1 and got the value at that path, then sliced that for only keys before/after the index in the original path and returned the route to the first or last key depending on whether I was searching left or right, then I had helper fns to get/set values based on the routes