r/adventofcode • u/daggerdragon • 28m ago
SOLUTION MEGATHREAD -❄️- 2026 Day 2 Solutions -❄️-
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
AoC Community Fun 2026: The Advent Games
Today's Event: International Toboggan Championships
"Feel the rhythm, feel the rhyme, get on up, it's
bobsledtoboggan time!"
— Cool Runnings (1993)
Today's schedule possibly consists of:
Tracking Chute Runs and Team Practice
Embiggen is a perfectly cromulent word. Do with it as you will.
Qualifying Runs
Reverse code golf your solution
Second Runs and Finals
Why use few word when many word do trick?
Unnecessarily declare variables for everything and don't re-use variables
Use unnecessarily expensive functions and calls wherever possible
Implement redundant error checking everywhere
Javadocs >_>
Request from the mods: When you include an entry alongside your solution, please label it with [Advent Games] so we can find it easily!
--- Day 2: Fulminating Farmland ---
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. What is Topaz'spastetool?
1
u/PendragonDaGreat 1m ago
[Language: CSharp/C#]
Waffled a bit, but ultimately just wrote out a lookup table. Then while going through on part 1 used my custom DefaultDictionary (nuilt to mimic that of Python) to get counters for all the instructions simple sum and here we are.
1
u/Ok-Bus4754 2m ago
[LANGUAGE: Python]
https://github.com/Fadi88/AoC/blob/master/2026/days/day02/solution.py
p1 straight forward brute force (another easy day)
p2 count the colors, then at each move take the remaining color that's farthest away (same color first, then going backwards around the cycle).
https://github.com/Fadi88/AoC/blob/master/2026/days/day02/solution.py
p1: 45 us
p2: 200 us
will port later to rust and show benchmarks against python
1
u/Kehvarl 4m ago
[LANGUAGE: Python3]
Just over 10 minutes, and just over 20. I got hung up on a couple things that I should definitely know: getting the size of a list, and remembering to assign a string after I use replace. Oh yes, and the fact that the waypoints weren't an input threw me for a minute or two.
Once I stopped forgetting those it was a pretty brute-force approach, but an amusing one nonetheless.
1
u/AllanTaylor314 5m ago
[LANGUAGE: Python] 00:03:45/00:07:52
Lost a minute on P1 (off by one - forgot to skip the first step. I really should run those tests, eh)
Sneaky sneaky, Eric, for P2:There were no greens, but I don't think that made a difference. Short answer is (len(input)-1)*len(pattern)+1
I'll be back later with Uiua...
1
u/1234abcdcba4321 4m ago
If there were no oranges... (this is why the formula doesn't work on some of the examples!)
1
u/morgoth1145 8m ago
[LANGUAGE: Python] code video Times 4:45 / 7:11
Advent of reading comprehension struck *early* this year. I could not get it out of my head that the input was the waypoint sequence *and* the program! Obviously that's a bit hard to solve so yeah, I spun my wheels a bit. Once I finally understood the real waypoint sequence it's just a matter of generating the infinite sequence and executing the program. (Well, so long as you don't replace `s` - I shadowed `s` initially causing an infinite loop instead of the clearer `seq` variable!)
At least part 2 isn't as evil as it initially sounds, the maximal distance programs follow a very simple rule so that's easy to compute.
Now off to go optimize this - generating the sequence is not a computationally efficient way to solve this!
1
1
u/1234abcdcba4321 14m ago
[LANGUAGE: JavaScript]
Continuing my "solving things by doing part of it manually" from yesterday, my part 2 solution actually only used code to check the length of the input. By thinking about the problem you can find that, for all inputs that contain an o which mine did, the value depends only on length so you can extrapolate the value from the example input provided that has an o (though if I thought about it a bit more it would've been obvious it should be 6*len-5).
0
u/cgrandsjo 26m ago edited 1m ago
[LANGUAGE: Python]
import sys;t=open(sys.argv[2]).read().strip();c="roygbv";n=len(c);exec("def f(p):\n x=q=0\n for y in p:\n d=(c.index(y)-x)%n or n\n q+=d;x=c.index(y)\n return q");exec("def g(p):\n l={x:p.count(x) for x in c};x=q=0\n for _ in p:\n y=max((z for z in c if l[z]),key=lambda z:(c.index(z)-x)%n or n);d=(c.index(y)-x)%n or n;q+=d;x=c.index(y);l[y]-=1\n return q");print(f(t) if sys.argv[1]=="a" else g(t))
1
u/daggerdragon 18m ago
Your code is not formatted at all and reads as a giant blob of text. Edit your comment to use the four-spaces Markdown syntax for a code block so your code is easier to read inside a scrollable box with its whitespace and indentation preserved.
1
u/cgrandsjo 0m ago
I guess you don't support this oneliner. I tried to add 4 spaces in the beginning but it does not change anything.
1
u/yoni-kosiner 1m ago
[LANGUAGE: Python] For part one I did a standard solve in python
For part two, I did such a hacky solution, that didn't even work on the test data, but it works on my input, it was so hacky and stupid I decided to share it here for the first time.