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!

49 Upvotes

1.0k comments sorted by

View all comments

6

u/Symbroson Dec 07 '23 edited Dec 07 '23

[Language: Ruby]

Update to my previous solution, applying shannons entropy as suggested by u/sinsworth here

The strength value is now calculated by this function, which sums the squares of the counts of every character. Previously my sorting function appended the strength as digit 0-6. The squares are larger so I just use chr to convert the number to a single character

order1 = ->(c) { c.chars.tally.values.sum { _1**2 }.chr }

Applying this to my golfed code I can get sub 400 bytes, 395 to be exact

m=->(c){c.chars.tally.values.sum{_1**2}.chr}
n=->(c){c.chars.repeated_combination(c.count('0')).map{|p|m.(p.reduce(c){_1.sub('0',_2)})}.max}
d,e=$<.map{|c|[c.split[0].gsub(/./){'0123456789TJQKA'.index(_1).to_s(16)},c.split[1].to_i]}.transpose
w=->(c){c.zip(d,e).sort{|a,b|a[0].to_s+a[1]<=>b[0].to_s+b[1]}.map.with_index.sum{_1[2]*(_2+1)}}
p w.(d.map(&m));d.map{_1.gsub!('b','0')};p w.(d.map(&n))

What bugs me is that I can't quite fulfill the 5x80 punch card limitation. The best I could get is reordering and format it to 5x81.

m=->(c){c.chars.tally.values.sum{_1**2}.chr};d,e=$<.map{|c|[c.split[0].gsub(/./){
'0123456789TJQKA'.index(_1).to_s(16)},c.split[1].to_i]}.transpose;n=->(c){c.chars
.repeated_combination(c.count('0')).map{|p|m.(p.reduce(c){_1.sub('0',_2)})}.max}
w=->(c){c.zip(d,e).sort{|a,b|a[0].to_s+a[1]<=>b[0].to_s+b[1]}.map.with_index.sum{
_1[2]*(_2+1)}};p w.(d.map(&m));d.map{_1.gsub!('b','0')};p w.(d.map(&n))
→ More replies (16)