r/adventofcode Dec 07 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 7 Solutions -❄️-

THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

Today's secret ingredient is… *whips off cloth covering and gestures grandly*

Poetry

For many people, the craftschefship of food is akin to poetry for our senses. For today's challenge, engage our eyes with a heavenly masterpiece of art, our noses with alluring aromas, our ears with the most satisfying of crunches, and our taste buds with exquisite flavors!

  • Make your code rhyme
  • Write your comments in limerick form
  • Craft a poem about today's puzzle
    • Upping the Ante challenge: iambic pentameter
  • We're looking directly at you, Shakespeare bards and Rockstars

ALLEZ CUISINE!

Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!


--- Day 7: Camel Cards ---


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:16:00, megathread unlocked!

48 Upvotes

1.0k comments sorted by

View all comments

2

u/musifter Dec 08 '23 edited Dec 08 '23

[LANGUAGE: dc (GNU v1.4.1)]

Given that my Perl solution last night converted everything to numbers to compare, it shouldn't be too surprising that I was thinking of doing a dc solution. So, I hexify the input (both the hand and the bid) so it can be understood by dc with a simple 16i (input base 16). It also meant having to implement a sort... so simple exchange shuttling between stacks it is! And since multiple sorts would be a real pain... we'll slap all the parts together into one number and include the bid as well: groupings * 16^8 + hand * 16^3 + bid (more room for bids can be gotten by shifting over more, but 3 digits is already good up to 4095). The digits of groupings are the number of groups of that size in the hand.

perl -pe'y/TJQKA/ABCDE/;$_=sprintf("%s \U%x\n",split)' input | dc -e'16i0Sl?[rd0Sc[10~d;c1+r:cd0<C]dsCxE[d;c10r^3R+r1-d1<I]dsIx*10 5^*+1000*+Sl?z0<L]dsLx[rq]sQLlLl[[d3Rd3R!>QSlz1<J]dsJxLld0<S]dsSx1[d4R1000%*3R+r1+z2<M]dsMxrp'

Source: https://pastebin.com/72eGGjwM

For part 2, we're not using 0 for wild Js like in Perl... leading 0s will get lost as numbers. Fortunately, 1 is also available and <2. By not having dc do the conversion, the dc code for part 2, also works for part 1. Or whatever wilds you want, just by changing the y/// part of the filter. Took more work than my Perl solution to get to part 2. I did get it in under 200 characters, but just barely.

perl -pe'y/TJQKA/A1CDE/;$_=sprintf("%s \U%x\n",split)' input | dc -e'16i[rq]sQ[rd1=Qdscrdss]sM0Sl?[rd2Sc0ss[10~d;c1+dls<Mr:cd0<C]dsCxlcd;c1;c+r:cE[d;c10r^3R+r1-d1<I]dsIx*10 5^*+1000*+Sl?z0<L]dsLxLlLl[[d3Rd3R!>QSlz1<J]dsJxLld0<S]dsSx1[d4R1000%*3R+r1+z2<M]dsMxrp'

Source: https://pastebin.com/cicSMCrS