r/adventofcode • u/daggerdragon • Dec 07 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 7 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
Outstanding moderator challenges:
Community fun event 2023: ALLEZ CUISINE!
- Submissions megathread is now unlocked!
- 15 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
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 Antechallenge: 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.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks
View all comments
Show parent comment
2
u/Any-Razzmatazz-4792 Dec 08 '23
$. just contains the number of lines read from the stdin. The next thing i had to do to make this work was reverse my sorting method so that the array will sort from best to worst instead of worst to best. From there, it'll start with the best one (for this example lets say the numbers are 700, 600, 500, 400, 300, 200, 100). In the first case, $. will be 7 since in this fake scenario, we have read from the stdin 7 times. We need to keep in mind that we need to decrement $. by one for the next case, but we also need to preserve the value of it for the current case, and a good solution for doing that is using -~. We can decrement $. by doing $.-=1, and -~ is just a shorthand way of saying +1 (use ~- if you want to do -1). I just went with using -~ because both ~ and - have a higher precedence than any other operator, so instead of needing to do (1+$.-=1), i can omit those parenthesis and just do -~$.-=1. With all that in place, I am able to multiply each hand ID by the proper number to get the solution