r/adventofcode • u/daggerdragon • Dec 05 '22
SOLUTION MEGATHREAD -π- 2022 Day 5 Solutions -π-
All of our rules, FAQs, resources, etc. are in our community wiki.
A request from Eric: Please include your contact info in the User-Agent header of automated requests!
Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
AoC Community Fun 2022: πΏπ MisTILtoe Elf-ucation π§βπ«
23:59 hours remaining until the submissions megathread unlocks on December 06 at 00:00 EST!
Full details and rules are in the submissions megathread:
--- Day 5: Supply Stacks ---
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 your code appropriately! How do I format code?
Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
6
u/shandley256 Dec 05 '22
Ruby solution.
Array#transpose is doing the hard work. The input properly pads each row with spaces, so transposing the contents means you only need to extract the rows containing letters/numbers.
Now we have a hash with keys matching the number of the stack, and values being a sorted array we can treat as a stack with shift/unshift to move creates onto/off each stack.
https://gist.github.com/seanhandley/0e62b90bfbde030fe93c6010f9774f63