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

6

u/Smylers Dec 02 '23

[LANGUAGE: Vim keystrokes]

This is for part 2 — as ever, just load your input, type this, then watch as the numbers dance up the screen:

:%s/.*: ⟨Enter⟩{O0⟨Esc⟩j
qaqqa:s/[,;] /⟨Ctrl+V⟩⟨Enter⟩/g⟨Enter⟩
:2,.sor!n⟨Enter⟩:.,']sor/ /⟨Enter⟩
v']J0wvfgFes*⟨Esc⟩wwvfdFns*⟨Esc⟩wwD0C⟨Ctrl+R⟩=⟨Ctrl+R⟩-⟨Enter⟩⟨Esc⟩0Dk@-⟨Ctrl+A⟩
jJ:redr|sl20m⟨Enter⟩@aq@a

Sorry I don't have time right now to explain it, but if you just type it in and watch what's happening, it should be clear enough. It relies on each game requiring at least 1 of each colour of cube, which was true for my input.

The :redr|sl20m is entirely gratuitous: it :redraws the window then :sleeps for 20 ms, just so we can see the state after each game has been processed, providing an animation of the loop.

3

u/Angevinz Dec 02 '23 edited Dec 02 '23

Hi, I'm trying to replicate your solution. I am getting stuck at:

:s/[,;] /⟨Ctrl+V⟩⟨Enter⟩/g⟨Enter⟩

What is the ⟨Ctrl+V⟩ supposed to do? Paste something? I am completely at loss here.

I would appreciate your help :)

Edit:

For anyone wondering the same: It's carriage return!

The idea behind the script is:

  1. Delete the first part before and including the colon and space after it (Game X:)

  2. Put zero on empty line at the top of the file (total sum)

  3. Jump one line down

  4. Start recording macro a

  5. Substitute all commas (,) and semi-colons (;) for new lines

  6. Sort the created lines by numerical value

  7. Sort the created lines again by color string

  8. Join all newly created lines into one line

  9. Take the first colour (blue) with its count

  10. Substitute all text between the highest blue count and highest green count with *

  11. Skip to highest red count

  12. Substitute all text between the highest green count and highest red count with *

  13. Delete everything after the red's highest count

  14. Evaluate the expression created on line (should be of format HIGHEST_BLUE * HIGHEST_GREEN * HIGHEST_RED)

  15. Put the result into register

  16. Delete empty line

  17. Add the intermediate result to the total sum

  18. Execute macro a (creates loop)

  19. Finish recording macro a

  20. Execute macro a

→ More replies (5)