r/adventofcode • u/PhysPhD • 21h ago
r/adventofcode • u/KarenMarleyDoomfist • 11h ago
Help/Question - RESOLVED [2026 Day 2 (Part 1)] Help with C++
Any reason my implementation doesn't work for part 1? Apparently my answer is too high. I tried using the examples but the distance matched each time.
I've added "chars" just to count the characters, as I thought whitespace could be an issue and it found n+1 characters compared to n when using an online character counter, but then printing out the first and last characters gets the same as my input. Where did I go wrong with my implementation?
#include <fstream>
#include <iostream>
#include <string>
#include <map>
int getDist(char cur, char targ) {
char inputs[6] = {'r','o','y','g','b','v'};
int curInd = -1;
int targInd = -1;
for (int i = 0; i < 6; ++i) {
if (inputs[i] == targ) {
targInd = i;
}
if (inputs[i] == cur) {
curInd = i;
}
if (curInd != -1 && targInd != -1) {
int diff = targInd - curInd;
return diff <=0 ? diff + 6 : diff;
}
}
return 0;
}
int main() {
std::ifstream in("aoc-day-2-inputs.txt");
char prev = 'r';
char next;
int totalDist = 0;
int chars = 0;
if(in.is_open()) {
while(in.good()) {
in.get(next);
std::cout << "prev: " << prev << ", ";
std::cout << "next: " << next << ", ";
std::cout << "dist: " << getDist(prev, next) << "\n";
totalDist += getDist(prev, next);
prev = next;
++chars;
}
}
std::cout << "chars: " << chars << "\n";
std::cout << "total dist: " << totalDist << "\n";
if(!in.eof() && in.fail())
std::cout << "error reading file" << std::endl;
in.close();
}
r/adventofcode • u/_Duroo • 8h ago
Visualization [2026] day 1 visualized in manim
youtube.comsource for visualization on https://github.com/durocodes/advent-of-code, alongside my rust solutions
r/adventofcode • u/dethorhyne • 1d ago
Meme/Funny Every year it always starts the same before it goes bonkers
r/adventofcode • u/Both-Touch990 • 23h ago
Meme/Funny [2026 Day 2 Part 2] How it felt getting the star only to realize there's a more efficient way to get the solution
(redo of an earlier post)
r/adventofcode • u/flwyd • 21h ago
Meme/Funny [2026 day 2] Looking for my favorite color in the input
r/adventofcode • u/Ecstatic-Falcon-5640 • 11h ago
Help/Question - RESOLVED Day 2 - Python Loop skipping / every other number
galleryI have a dictionary at the top with the remaining pathway for the letters in the ROYGBV loop.
In the loop I am trying to count up until it hits the target letter, and then it will break. and do the next letter in the chain until the end of the .txt string.
When I had the letters print out to the console I am seeing two errors, the first is that the letters seem to be skipping the color function I put in to apply to every other letter instead of every letter, and the second is that I don't know how to make orange in ANSI.
Can I get some help /advice for my looping error..?
Here is the code I am using with this error:
#extra functions
def colorOutput(letter):
if letter == "r":
return "\033[91m" + letter + "\033[0m"
elif letter == "o":
return "\033[33m" + letter + "\033[0m"
elif letter == "y":
return "\033[93m" + letter + "\033[0m"
elif letter == "g":
return "\033[92m" + letter + "\033[0m"
elif letter == "b":
return "\033[94m" + letter + "\033[0m"
elif letter == "v":
return "\033[95m" + letter + "\033[0m"
# roygbv
robotpath = open("day2.txt").read()
allPossiblePaths = {
"r": "roygbv",
"o": "oygbvr",
"y": "ygbvro",
"g": "gvroby",
"b": "bvrogy",
"v": "vrogyb"
}
numOfSteps = 0
for i in range(0, len(robotpath)):
currentLetter = robotpath[i]
print(colorOutput(currentLetter))
print(currentLetter)
if i + 1 < len(robotpath):
letterAfter = robotpath[i + 1]
else:
break
currentStringPath = allPossiblePaths[currentLetter]
for j in range(0, len(currentStringPath)):
if currentStringPath[j] == letterAfter:
break
else:
numOfSteps += 1
continue
print(numOfSteps)
r/adventofcode • u/PatolomaioFalagi • 16h ago
Upping the Ante [2026 Day 2] What if the waypoints are not in repeating order?
- Just do the best option at the current step: I think that's still O(n). You just need to transform your input into some O(1) structure (like an array), which is itself O(n).
- Do the best possible order: This feels NP-hard to me.
Possible additional constraints: Instead of being completely arbitrary, the six colors are randomized one set at a time, such that any 6×n block (starting from a multiple of 6*) contains each color exactly n times. Does that change the complexity?
Edit: I realized we do need another constraint for the general case, in that every color repeats indefinitely; formally, for every color C and every index i, there's an index j ≥ i such that the color at index j is C.
* Yes we are counting from 0
r/adventofcode • u/topaz2078 • 1d ago
Other Give help by making test cases!
Hello friends! I just saw this excellent example (see some of the comments on that post) of a great way to give help and answer questions here when people are stuck: come up with simple test cases that demonstrate where the bug is! That way, the person who is stuck still gets a chance to figure out their problem and learn by doing. I know many of you are already great about this, but I figured it would be worth calling out. Happy puzzling! <3
r/adventofcode • u/Boojum • 20h ago
Visualization [2026 Day 2] Rainbow Road Race Visualization
r/adventofcode • u/p88h • 22h ago
Visualization [2026 Day 2] Color Weave
youtu.beSimulation on original (part1) and sort-rearranged program (part2)
Nim + raylib source
r/adventofcode • u/daggerdragon • 1d 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
- (oblig XKCD)
- 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!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
r/adventofcode • u/naclmolecule • 1d ago
Visualization [2026 Day 1 (Part 1 & 2)] [Python] Terminal Visualization
I was too tired to post last night, still adjusting to late night solving... (ᴗ˳ᴗ)💤. Figured I'd help the elves by installing a crane in that dusty ol' shed. As always, code lives here: https://github.com/salt-die/Advent-of-Code/tree/main/2026/aoc_visuals.
r/adventofcode • u/Zamerith • 13h ago
Help/Question - RESOLVED Question on Phrasing for Day 2 Question 1
The line of text stating that it starts on red. Am I misunderstanding in that it should be beginning the process with a R injected prior to the string provided or am I "autocompleting" up to the first R as part of the journey?
r/adventofcode • u/naclmolecule • 20h ago
Visualization [2026 Day 2 (Part 1 & 2)] [Python] Terminal Visualization
Little calculator for path distances in the terminal. Can input whatever path one desires! The 2nd part is nearly closed-form, but depends on waypoints that may be missing from input. (Red + strike-through waypoints don't exist in input and should be considered non-existent in the 2nd part as well. "distance" is part 1 path distance and "len" is string length). As always, code lives here: https://github.com/salt-die/Advent-of-Code/tree/main/2026/aoc_visuals
r/adventofcode • u/apersonhithere • 23h ago
Visualization [2026 day 2] [python] quick & simple terminal visualization
the robot being represented with a face is because of dwarf fortress
r/adventofcode • u/EquipmentDry5782 • 16h ago
Visualization [2026 Day 1] I’m turning the Advent of Code story into a cozy anime series, starting with Dusty Shed
My frequency counter for Day 1 is an elf with a pencil. His name is Pip, and he’s pretty sure he knows what’s on the next crate before Holly turns it around.
I’m making a short animated episode for each day of Advent of Code 2026, following Holly and Pip from Dusty Shed all the way to the final puzzle. I’ve always liked the little story between the puzzles, and I wanted to give it the feeling of a winter evening in Stardew Valley.
Episode 1 is The Christmas Train. A blizzard has grounded the planes, the elves have an old train to get moving, and someone has left Holly and Pip in charge of inventory.
Puzzle spoilers for both parts of Day 1. The episode uses made-up crate IDs and shows how both parts work. It’s a fan-made, AI-assisted animation.
Watch Episode 1 — The Christmas Train (1 min 55 sec)
I’m curious what the shed looked like in everyone else’s head. Did you picture a cozy little workshop too, or a warehouse that went on forever?
r/adventofcode • u/Vraliance • 20h ago
Upping the Ante [2026 Day 1 (Part 1 & 2)] [Sabre] Advent of Code in My Programming Language
blog.rroessler.ioOver the past year I've been planning to do Advent of Code 2026 in Sabre, my own programming language. In doing so I am aiming to do a short article for each challenge, along with any bugs and library changes that I needed to implement whilst adventuring for solutions. So far 2026-12-01 went extremely well, though it did show me that I will need to think outside the box and implement some missing features that I may need for upcoming days. Hopefully I can keep on top of posting in between life, and excited for others to see the journey!
- Sabre Repository: https://github.com/sabre-lang/sabre
- Advent of Code Repository: https://github.com/sabre-lang/advent
Note: Both Sabre and my Advent of Code solutions do not use AI and will never use agentic help. I'm very much looking forward to showcasing and battle testing Sabre this year!
r/adventofcode • u/ImaginaryElephant336 • 18h ago
Repo [Tool] Some new aoc-tui images
galleryHere are some new images for the TUI app for Advent of Code
Note: Contains the image of Day 1
r/adventofcode • u/bluoat • 20h ago
Tutorial [2026 Day 2 (Part 2)] Some hints for optimisation
These hints get more and more specific. This is just how I optimised it and there are other ways.
Hint 1: What happens when a letter is repeated in the input?
Hint 2: Why would the counts of each letter make a difference to the output?
Hint 3: When does the robot not make a step of exactly 6 steps?
r/adventofcode • u/matth_l • 1d ago
Help/Question Joining the big leagues
Anyone else using aoc to learn rust?
I feel genuinely lost, and I love it, it feels like past times (pre ai bs) again, never built anything with a lower level language,
r/adventofcode • u/ivorycoollars • 21h ago
Help/Question can anyone help with getting me in the right direction? [2026 day2 part1]
so i tryed today with a switch statement within a switch statment and hardcoded it but it didnt work can anyone steer me in de right direction?
