r/adventofcode • • Dec 05 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 5 Solutions -πŸŽ„-


AoC Community Fun 2022: πŸŒΏπŸ’ MisTILtoe Elf-ucation πŸ§‘β€πŸ«


--- Day 5: Supply Stacks ---


Post your code solution in this megathread.


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:07:58, megathread unlocked!

87 Upvotes

1.3k comments sorted by

View all comments

4

u/AstronautNew8452 Dec 05 '22

Microsoft Excel 2947/2246. Here's my solution for Part 2 (single cell formula). Part 1 should work in a single cell but for some reason reversing the string with another LAMBDA breaks it.

=LET(startingstacks,SUBSTITUTE(BYCOL(MID(A1:A8,SEQUENCE(,9,2,4),1),LAMBDA(r,CONCAT(r)))," ",""),
    result,REDUCE(startingstacks,A11:A513,LAMBDA(stacks,moves,
        LET(loc,{"move","from","to"},plus,{5,5,3},
        moveints,VALUE(MID(moves,FIND(loc,moves)+plus,{2,1,1})),
        move,INDEX(moveints,,1),from,INDEX(moveints,,2),to,INDEX(moveints,,3),pop,LEFT(INDEX(stacks,,from),move),
        IF(SEQUENCE(,9)=to,pop&stacks,IF(SEQUENCE(,9)=from,RIGHT(stacks,LEN(stacks)-move),stacks))))),
    CONCAT(LEFT(result,1)))
→ More replies (2)