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!

50 Upvotes

1.0k comments sorted by

View all comments

1

u/Markavian Dec 07 '23

[LANGUAGE: JavaScript]

Had help from here: https://www.reddit.com/r/adventofcode/comments/18cr4xr/2023_day_7_better_example_input_not_a_spoiler/

My original (intended) solution for part two was correct... but I'd sorted the lowest common card to add jokers to instead of the the highest common cardand that was enough to get the wrong answer after fixing all the other bugs that I spotted myself.

Part 1 went pretty smoothly. I was disappointed that I couldn't think of / find any standard datastructures for counting occurances; but I was glad to implement my own version - because that meant I could make a second one for counting occurances with jokers... which seems like a really clean way to solve for the second star if I may say so myself... also descriptive classifications in my output.json was really helpful in debugging, so +1 for over-engineering.

https://github.com/johnbeech/advent-of-code-2023/blob/main/solutions/day7/solution.js

https://github.com/johnbeech/advent-of-code-2023/blob/main/solutions/day7/output-part1.json

https://github.com/johnbeech/advent-of-code-2023/blob/main/solutions/day7/output-part2.json

2

u/daggerdragon Dec 07 '23 edited Dec 08 '23

FYI: do not share your puzzle input which also means do not commit puzzle inputs to your repo without a .gitignore.

Please remove puzzle inputs from your repo and scrub them from the commit history as well. edit: 👍

2

u/Markavian Dec 08 '23

Ooh bonus tasks stretching back to 2015. Yay!

I'll get right on that.

2

u/Markavian Dec 08 '23
echo "input.txt" >> .gitignore
git add .
git commit -m "Ignore input.txt based on AoC license restrictions"
git filter-repo --path-glob **/input.txt --invert-paths
git push origin --force

1

u/Markavian Dec 08 '23

Refined into:

Wipe out all input.txt files from the repo history using git filter-repo and a force push; and add a .gitignore record for good measure.

repolist-aoc.txt:

johnbeech/advent-of-code-2015
johnbeech/advent-of-code-2016
johnbeech/advent-of-code-2017
johnbeech/advent-of-code-2018
johnbeech/advent-of-code-2019
johnbeech/advent-of-code-2020
johnbeech/advent-of-code-2021
johnbeech/advent-of-code-2022
johnbeech/advent-of-code-2023

Command:

npx github:connected-web/jumper --repoList repolist-aoc.txt --strategy aoc

Example logs:

[Fri Dec 08 2023 01:01:13 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] git clone git@github.com:johnbeech/advent-of-code-2015.git repos/johnbeech/advent-of-code-2015 from /home/markavian/Local/jumper
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] Cloning into 'repos/johnbeech/advent-of-code-2015'...
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] pwd from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] echo "
input.txt" >> .gitignore from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015]
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] echo "
example.txt" >> .gitignore from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015]
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] echo "
tes*.txt" >> .gitignore from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015]
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] git add .gitignore from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015]
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] git commit -m "Ignore input.txt based on AoC license restrictions" from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] [main ab3f2c0] Ignore input.txt based on AoC license restrictions
1 file changed, 6 insertions(+), 1 deletion(-)
[Fri Dec 08 2023 01:01:15 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] git filter-repo --path-glob **/input.txt --invert-paths --force from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:16 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] Parsed 85 commitsHEAD is now at 908a80c Ignore input.txt based on AoC license restrictions

New history written in 0.48 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
Completely finished after 0.94 seconds.
[Fri Dec 08 2023 01:01:16 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] git filter-repo --path-glob **/example.txt --invert-paths --force from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:17 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] Parsed 74 commitsHEAD is now at 908a80c Ignore input.txt based on AoC license restrictions

New history written in 0.01 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
Completely finished after 0.48 seconds.
[Fri Dec 08 2023 01:01:17 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] git filter-repo --path-glob **/tes*.txt --invert-paths --force from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:18 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] Parsed 74 commitsHEAD is now at 908a80c Ignore input.txt based on AoC license restrictions

New history written in 0.01 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
Completely finished after 0.70 seconds.
[Fri Dec 08 2023 01:01:18 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] git push --set-upstream git@github.com:johnbeech/advent-of-code-2015.git main --force from /Local/tmp/repos/johnbeech/advent-of-code-2015
[Fri Dec 08 2023 01:01:20 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] Branch 'main' set up to track remote branch 'main' from 'git@github.com:johnbeech/advent-of-code-2015.git'.
[Fri Dec 08 2023 01:01:20 GMT+0000 (Greenwich Mean Time)] [johnbeech/advent-of-code-2015] Writing log file to ./logs/johnbeech-advent-of-code-2015.log from /Local/tmp/repos/johnbeech/advent-of-code-2015

Example (no input.txt):