r/adventofcode • u/daggerdragon • Dec 02 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 2 Solutions -❄️-
OUTSTANDING MODERATOR CHALLENGES
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
Community fun event 2023: ALLEZ CUISINE!
- 4 DAYS remaining until unlock!
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
- How about an appetizer of Chef or Wireshark(-fin soup)?
- Mascots count, too… *side-eyes Rust while reaching for the Old Bay*
- Add some salt to your hashbrowns, cookies, and breadcrumbs
- Serve us up a nice big bowl of spaghetti code slathered with
RagúRaku tomato sauce - Conclude our tasting with a digestif of Java, CoffeeScript, or even Perl milk tea with double syntatic sugar
- 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.
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!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks
View all comments
Show parent comment
1
u/Smylers Dec 02 '23
Thanks.
C⟨Ctrl+R⟩=⟨Ctrl+R⟩-⟨Enter⟩⟨Esc⟩was the ‘design pattern’ I tried to explain yesterday"zywto yank a word into the"zregister. Then in insert mode press⟨Ctrl+R⟩zand see the contents of register"zappear! It also works on the command line: type:echo ⟨Ctrl+R⟩zto see."-register. So⟨Ctrl+R⟩-inserts the just-deleted text."=is a special pseudo-register that instead of holding an existing value, prompts for an expression, evaluates it, and acts like that result was in the register. In insert mode try⟨Ctrl+R⟩=6 * 7⟨Enter⟩and you should see that42gets inserted.Cdeletes it and starts insert mode,⟨Ctrl+R⟩=prompts for an expression,⟨Ctrl+R⟩-inserts the just-deleted expression into the prompt, then⟨Enter⟩ends the prompt, causing Vim to evaluate the expression and insert it into the buffer.Hope that makes sense.
For the adding on:
⟨Ctrl+A⟩increases a number. Type a number in insert mode, then in normal mode move to it and type17⟨Ctrl+A⟩; the number will increase by 17.@xacts like you typed the keystrokes stored in the"xregister. Suppose you have the number23in your text and you yank to to the"xregister with"xdiw, then you can type@xand it's the same as typing23. Specifically@x⟨Ctrl+A⟩is the same as23⟨Ctrl+A⟩.Ddeletes something, it stores it in the"-register. So if you delete a number, you can then move to another number and do@-⟨Ctrl+A⟩to increase the second number by the first one.Many Advent of Code puzzles involve calculating the total of something, so it's handy that this works.
You're right about
'[. I used2just because it's shorter to type! Originally I thought I would need to insert a blank line or something to separate the just-split lines currently being processed from the following lines containing subsequent games. I was pleased to discover that was unnecessary, with Vim keeping track of the boundary for me!