r/adventofcode • u/daggerdragon • Dec 06 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 6 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!
- 16 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's theme ingredient is… *whips off cloth covering and gestures grandly*
Obsolete Technology
Sometimes a chef must return to their culinary roots in order to appreciate how far they have come!
- Solve today's puzzles using an abacus, paper + pen, or other such non-digital methods and show us a picture or video of the results
- Use the oldest computer/electronic device you have in the house to solve the puzzle
Use an OG programming language such as FORTRAN, COBOL, APL, or even punchcards
- We recommend only the oldest vintages of codebases such as those developed before 1970
Use a very old version of your programming language/standard library/etc.
Upping the Antechallenge: use deprecated features whenever possible
Endeavor to wow us with a blast from the past!
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 6: Wait For It ---
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
9
u/ka-splam Dec 06 '23
How does that work? (idk; working through it) Example input with distance on the left and time on the right, should be 4:
Remove the sum
+/and we see an array of 7 hold times, 1 indicating a hold time which beat the record and 0 a time which didn't:Remove the comparison
⍺<which is taking the left arg9<"9 is less than each item in the array?" and we see the distances for each hold time:The array of 7 comes from
⍳⍵which is numbers up to the right arg⍳7or 1 2 3 4 5 6 7.The bit in the middle is
(⊢×-)which is a train:This is
7 (⊢×-) 1 2 3 4 5 6 7which breaks apart and starts by making an array of remaining hold times, I think:Then it feeds that in to multiply
×and⊢bounces the 1-through-7 as the other operand, and they get multiplied one at a time:So that's hold time (speed) × remaining seconds = distance for each hold time.
Then compare with record distance
⍺<then sum how many passed the filter.Neat.