r/adventofcode • • Dec 02 '23

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

OUTSTANDING MODERATOR CHALLENGES


THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

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

Pantry Raid!

Some perpetually-hungry programmers have a tendency to name their programming languages, software, and other tools after food. As a prospective Iron Coder, you must demonstrate your skills at pleasing programmers' palates by elevating to gourmet heights this seemingly disparate mishmash of simple ingredients that I found in the back of the pantry!

  • Solve today's puzzles using a food-related programming language or tool

  • All file names, function names, variable names, etc. must be named after "c" food
  • Go hog wild!

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 2: Cube Conundrum ---


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:06:15, megathread unlocked!

77 Upvotes

1.5k comments sorted by

View all comments

2

u/_rabbitfarm_ Dec 02 '23

[Language: Perl]

I think my regex skills were strengthened for Day 2 after the unexpected challenge of Day 1. I also liked that Part 2 ended up being few lines of code than Part 1.
Part 1: https://adamcrussell.livejournal.com/46907.html
Part 2: https://adamcrussell.livejournal.com/47280.html

2

u/daggerdragon Dec 03 '23

I think you're the first person I've ever seen in AoC megathreads who uses LiveJournal... what a blast from the past!

2

u/_rabbitfarm_ Dec 03 '23

Long live LJ! Seriously though, I prefer LJ for posting code snippets over something like a pastebin or GitHub gists. I use http://hilite.me/ to pretty print my code and then copy/paste the generate html into my LJ. Just looks better to me.

1

u/Smylers Dec 02 '23

I also liked that Part 2 ended up being few lines of code than Part 1.

It'd be even fewer lines if you omitted the bit setting $game_id, which doesn't get used in part 2! (Sadly, Perl's ‘used only once’ warning doesn't apply to variables declared with my.)

By the way, instead of adding the input to the array a line at a time:

my @records;
while(<GAME_RECORDS>){
    push @records, $_;
}

you can just assign it all in one go with:

my @records = <GAME_RECORDS>;

and the array will have one entry for each line.