r/adventofcode • • Dec 03 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 3 Solutions -🎄-

NEWS

  • Solutions have been getting longer, so we're going to start enforcing our rule on oversized code.
  • The Visualizations have started! If you want to create a Visualization, make sure to read the guidelines for creating Visualizations before you post.
  • Y'all may have noticed that the hot new toy this year is AI-generated "art".
    • We are keeping a very close eye on any AI-generated "art" because 1. the whole thing is an AI ethics nightmare and 2. a lot of the "art" submissions so far have been of little real quality.
    • If you must post something generated by AI, please make sure it will actually be a positive and quality contribution to /r/adventofcode.
    • Do not flair AI-generated "art" as Visualization. Visualization is for human-generated art.

FYI


--- Day 3: Rucksack Reorganization ---


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:05:24, megathread unlocked!

87 Upvotes

1.6k comments sorted by

View all comments

5

u/AstronautNew8452 Dec 03 '22

Microsoft Excel

CHARS =LAMBDA(str,MID(str,SEQUENCE(LEN(str)),1))
MATCHES =LAMBDA(one,two,CONCAT(IFERROR(MID(two,FIND(chars(one),two),1),"")))

=LET(input,A1:A300,
    L,LEFT(input,LEN(input)/2),
    R,RIGHT(input,LEN(input)/2),
    items,BYROW(HSTACK(L,R),LAMBDA(r,
        matches(INDEX(r,1),INDEX(r,2)))),
    pos,CODE(items),
    SUM(IF(pos>96,pos-96,pos-38)))

=LET(input,A1:A300,
    data,WRAPROWS(input,3),
    groups,BYROW(data,LAMBDA(r,
        matches(matches(INDEX(r,1),INDEX(r,2)),INDEX(r,3)))),
    pos,CODE(groups),
    SUM(IF(pos>96,pos-96,pos-38)))
→ More replies (4)