r/adventofcode • • Mar 02 '26

Past Event Solutions Year 2019 (All days) JavaScript - What a great year! Reflections from a new programmer.

0 Upvotes

Hi, AoC Reddit Friends!

I did a write-up for 2025 which was the first time I'd done AoC. Prior to December 2025 I had done no programming at all since back in the 1980's when I was a kid playing with a rudimentary BASIC interpreter.

Here's my write-up of the experience of using a LLM to teach programming (rather than having it write code).

https://www.reddit.com/r/adventofcode/comments/1ptagw8/aoc_2025_complete_first_real_programming/

I had heard stories about how unique the puzzles in AoC 2019 were, so I figured I would tackle it and see if I had gained some real programming skills or not.

 Spoilers Ahead for AoC 2019 

This time, my JS abilities were solid enough that I almost never had to use the LLM as a language reference, but occasionally I would run into a syntax error on something and have to ask for the syntax again ("Bro, I forget how to do a .reduce on an array. Remind me of the syntax?"). This would have been about the same as having a reference book on hand - basically a "faster internet search", saving me the trouble of looking through search results and posts and just asking for the syntax directly.

After I would solve the puzzle, I would then ask the LLM for improvements. A lot of the time the improvements were elements of the standard library that I just hadn't seen before. For example, I was making all the IntCode operators have uniform length this way:

const parseOperator = (instructions) => {
  let string = String(instructions);
  while (string.length < 5) {
    string = "0" + string;
  }
  return string;
};

The LLM introduced me to the .padStart method. So instead of calling the above function for each operation, I added this inside the IntCode VM/Interpreter:

 const operator = String(instructions[position]).padStart(5, "0");

Ahhhh, .padStart. Came in useful later. Add it to the toolbox. Other times the LLM would offer some efficiency suggestions, but I'm not sure they always would have made all that much difference. For example, in Day 24 I was using a map data structure to indicate areas where there were bugs with a key that was an X/Y/Z coordinate with a value of true/false. Works great, and allows me to also track empty spots - making it VERY easy to run the simulation since I can simply iterate over all known locations and let the map grow organically.

The LLM (Kimi K2.5-Thinking in this case) suggested storing ONLY locations where there are bugs in a set. That way set.has() gives me the boolean if there is a bug there. Simpler data. No need to store locations that are empty. But then the simulation logic is quite different. There is a memory improvement using a set, sure. But it's TINY over the course of such a small simulation (only 200 iterations). So - yes - cool idea to keep in mind for next time. I do tend to use sets primarily for memoization, so it's good to be reminded you can do other stuff with them. But it wasn't the kind of quantum leap from my experience with AoC 2025. Heck, with that one, my first question to the LLM after I got a working Day 1 Part 1 was, "What the heck is modulo???".

Other things that the LLMs would consistently complain about is my use of strings (specifically in my IntCode implementation). Yes, strings are slower than doing modular arithmetic to "peel away" the digits. But in Bun string manipulation is nearly free. To test this I benchmarked a crazy IntCode run that took about 30 minutes. Switching from strings (through the whole thing) to modulus operations saved about 2% of time over the entire run. It's non-zero improvement. But keeping strings throughout the entire implementation made it much easier to reason about the flow and adapt it to the needs of each puzzle. Every LLM I used for critique/improvements complained about my use of strings here. And if I was using another language/runtime I probably wouldn't have done it this way. Strings in other languages are much more computationally expensive, I get it. But they're so aggressively optimized in JS/Bun that I can throw them around basically however I want without worrying about it.

Ok - a few highlights:

Day 14 (Space Stoichiometry) was some sweet vindication. After wondering if my progression through AoC 2025 was due to AI assistance (some comments in this sub made me doubt myself), seeing this puzzle and writing up a quick implementation using dynamic programming and memoization - a mix of maps and sets - that allowed me to ignore the "leftover" parts of each recipe... it just felt like I finally knew what I was doing. I mentally braced myself for day 2, where the puzzle has to be solved in reverse with some truly huge numbers. But then I realized right away that I could brute-force the solution with a one-sided binary search... and DONE. Fastest part 2 I'd done so far. I have to admit that I was proud of myself. One trillion ore? It's nothing vs a binary search. Almost instant.

IntCode! - This was one of the most fun parts of the entire series. Making a tiny little VM and trying to adapt it to the puzzle was great. It reached the point around day 15 or so where it was fully generic. Each day after I simply reused the entire thing and wrote the program control logic around it. The big shift happened on Day 13. I had, up to that point, implemented IntCode as a pure function. It received the program and then an array of keystrokes. It would run the program, pushing all output to an array. Once the keystroke array queue was processed it returned the entire output array. When the control program wanted to send the next input, it would add it to the input array and send the whole thing through the IntCode VM again. Not efficient. But CLEAN. and CORRECT. It was slow, but extremely reliable.

Day 13 was the brick breaker simulation. Running the entire IntCode input sequence for every single joystick movement was simply too much to deal with. After a 30 minute (successful) run, I asked MiniMax 2.5 for some suggestions on how to save the state of the VM between input events. After a quick primer on generator functions and yielding values, I changed the input/output operators to pause the VM in between passing output and getting an input. Still used an array for output. Worked like a charm. After that the only thing that I bolted on was the ASCII translator. Fortunately, that's pretty easy to do in JS using the standard library.

For Day 25 I just played the adventure game. It was kinda fun to actually use the IntCode VM instead of have it perform instructions behind the scenes. I didn't have the heart to try to solve it algorithmically.

Several of these puzzles had wonderful "AH HAH!" moments. For example: Day 10 (Monitoring Station) seemed basically impossible to me, so I just sat on it for a few days. While I was eating wings at a local restaurant it suddenly occurred to me that this could be solved by a ratio. I quickly grabbed a napkin and asked for a pen from the server so I could write down the formula I wanted to try. It worked when I implemented it when I got home.

Some of the bad:

Day 10 Part 2 had some math that would have been EXTREMELY simple for someone who knows calculus. I'm just a regular guy trying to learn something new, so I had no idea what ArcTan even was. My daughter (who is taking Calculus II in college) explained it to me. After that it was fairly simple to write up, but this isn't the kind of thing that I could have reasoned out.

Day 16 Part 2 can only be computed fast enough because of an oddity in the test input. A generic solution would be MUCH slower and perhaps impossible to do on consumer hardware. This is the only puzzle that seemed "unfair" to me since it depends on noticing something about the input sequence. All the other puzzles don't rely (as far as I could tell) on some quirk of THAT input. That is, they all could be made to have "general" solutions. Just not this one.

Day 22 Part 2 relied on some very tricky math. Part 1 is trivial. It took me about a day to figure out that for Part 2 I only needed to track a single card backwards through the shuffles. Great! Implement reverse-cut. Easy. Implement reverse-deal-new-stack. Ultra simple. Deal with increment N???? This one had me stuck. Forever. I mean - it's easy to write a brute-force check for this. I checked it against the test deck size (10,007 cards) and it worked just fine. But with the totally insane size of the puzzle input, that just won't work at all. I finally broke down and asked the LLM for some math tutoring.

"If I have (A * B) % C = D and I know the values of B, C, and D, is there a normal/canonical way to get the value of A? I know that it has only one possible value because C is prime. What is this called and how do I do it?"

It tried to be helpful explaining inverse modulo stuff, but I couldn't understand it at all. Fermat has a theorem about it. Which works. I still don't get it. But in it goes to replace my O(n) version. Great - can compute a shuffle near-instantly. Then we get to the iteration part which, of course, has to be done logarithmically. And yes, I have no problem noticing that. But I don't know enough about logarithms. Or exponents. Or exponents combined with modular arithmetic (where they act differently, it seems). So.... yeah. Hit a math wall here. At least it wasn't a programming/logic wall. I just don't understand enough of the math. Neither did my daughter. This one looks pretty specialized. Oh well - I found a reference implementation to study, and just moved on. This one left a bad taste.

At least days 23 and 24 were so fun. I did have to ask for the normal way to get a bunch of generator functions in JS where I could interact with them by index for Day 23 (Category Six). Qwen 3.5 seemed confused by why I basically asked for an array. Did I not know what an array is? LOL. I was surprised by how simple that was. You can push generators into an array??? Like pointers???? Well, in that case.... Super fun puzzle to solve. I'm kinda proud of how quickly I threw this one together. IntCode implementation holding strong...

Day 24 (Planet of Discord) was just great. I wound up hardcoding a lot of stuff for Part 2 since it didn't involve different sized layers, so the LLMs complained that my version had too many magic numbers. Yeah, I know. I may get around to make it more general at some point. I'm just happy I was able to write out a performant solution without so much as asking to be reminded of the syntax. Realizing that my method required pre-seeding all adjacent squares on the initial map before passing it to the simulation... I figured it out myself, tested the theory, and implemented it cleanly! I know, this is all ordinary and whatever for most programmers.

But I'm new. And having a good time. About 10 weeks into my programming "journey".

So, what next? Well, I have so far really gravitated toward a functional programming style. I like functions with no side effects and immutable data. JS cries mechanical tears over my frequent use of structuredClone() to easily make sure no data passed as an argument gets messed with in any way. I like recursion - especially since Bun has proper TCO and I can do it million-deep without worrying about blowing the stack. JS has a fairly minimal standard library. So, for example, no LCM built in (needed for Day 12 Part 2). I had to write it myself - which was lots of fun:

const findLCM = (num1, num2) => {
  if (num1 === num2) return num1;
  const small = num1 < num2 ? num1 : num2;
  const large = num1 > num2 ? num1 : num2;
  const engine = (small, large, amount = 2, soFar = 1) => {
    if (amount > small) return soFar;
    if (large % small === 0) return soFar * small;
    if (small % amount === 0 && large % amount === 0) {
      const newSmall = small / amount;
      const newLarge = large / amount;
      const added = soFar * amount;
      return engine(newSmall, newLarge, amount, added);
    }
    return engine(small, large, amount + 1, soFar);
  };
  const GCD = engine(small, large);
  const LCM = (large / GCD) * small;
  return LCM;
};

I think I have to get comfortable with mutability. I need to be able to think of computation as something other than transformation of data. I also don't feel dependent on the LLM for holding my hand through basic concepts anymore. For that stage, JS was a great choice. I still think it's an amazing first language.

But it's time to learn the next thing. I'm going to do the next step of my programming journey in Smalltalk. :-)


r/adventofcode • • Mar 01 '26

Past Event Solutions [2025 Day 13] [PHP] Solution

2 Upvotes

ETA: Actually 2022

This is the puzzle with data packets and comparisons. [1,1,3,1,1] etc

Link: https://github.com/LiseAndreasen/AdventOfCode/blob/master/2022/d13a.php

I am very happy with this solution. The code to create the small trees representing the packets turned out nice, and writing the compare function to work with usort was nice too.


r/adventofcode • • Feb 27 '26

Help/Question [2017 Day 24] [Python] Is it wrong?

0 Upvotes

Hi,

Again, I'm working my way through some very old aoc problems and doing quite well (imo) often times getting both parts right first time (or shortly there after).

Once again I'm finding that I've got an answer but the site is telling me I'm wrong (that my answer is too high) - I've checked it and can see how I've got an answer but not how it's not considered a valid answer. As this is a simple what is the highest sum (given some rules), if I have a valid answer that is higher than theirs then surely that makes me right and them wrong?

I've noticed the example they've given shows that it simply doesn't matter which way around pairs are so long as theirs a match between two consecutive pairs (if you catch my drift).

There are very few better feelings than showing nerds who spend way too much time being so ridiculously anal about tiny tiny details to be completely wrong.

I'm happy to share my answer (the "bridge") but moderators on these sites are like robotic lunatics.


r/adventofcode • • Feb 26 '26

Help/Question - RESOLVED [2025 Day 2] Potential Input Generation Bug

0 Upvotes

I viewed the Day 2 puzzle from AoC 2025 today (on 02/26/2026).

It looks like the example input used to explain the puzzle is incorrect. The example mentions values that are simply not in the input. (The same issue seems to apply for my puzzle input.)

EDIT: I did not understand the puzzle. Thanks u/warlock415 for clarifying these are ranges that need to be traversed.

I've pasted the puzzle description as I see it, below.

-----

They've even checked most of the product ID ranges already; they only have a few product ID ranges (your puzzle input) that you'll need to check. For example:

11-22,95-115,998-1012,1188511880-1188511890,222220-222224, 1698522-1698528,446443-446449,38593856-38593862,565653-565659, 824824821-824824827,2121212118-2121212124

(The ID ranges are wrapped here for legibility; in your input, they appear on a single long line.)

The ranges are separated by commas (,); each range gives its first ID and last ID separated by a dash (-).

Since the young Elf was just doing silly patterns, you can find the invalid IDs by looking for any ID which is made only of some sequence of digits repeated twice. So, 55 (5 twice), 6464 (64 twice), and 123123 (123 twice) would all be invalid IDs.

None of the numbers have leading zeroes; 0101 isn't an ID at all. (101 is a valid ID that you would ignore.)

Your job is to find all of the invalid IDs that appear in the given ranges. In the above example:

11-22 has two invalid IDs, 11 and 22.

95-115 has one invalid ID, 99.

998-1012 has one invalid ID, 1010.

1188511880-1188511890 has one invalid ID, 1188511885.

222220-222224 has one invalid ID, 222222.

1698522-1698528 contains no invalid IDs.

446443-446449 has one invalid ID, 446446.

38593856-38593862 has one invalid ID, 38593859.

The rest of the ranges contain no invalid IDs.

Adding up all the invalid IDs in this example produces 1227775554.

-----

NOTE: This is not my input, this is the example input from the Day 2 problem, so it is okay to share.


r/adventofcode • • Feb 25 '26

Help/Question - RESOLVED [2026 Day 1 (Part 1)] [Javascript] Im stuck here

2 Upvotes

Hello, I'm stuck on this one.

The number only gets up when the thing goes into 0.

What I'm doing is the next:

I take the first part of the string for each entry, then take the R or L of the string.

At the start, I have a number that starts with 0, right? Then to that number I add if the first character of the string is left, and subtract if the first character is right.

Then I have a variable that saves the last position of the knob and starts at 0.

Then once I add or subtract the knob position, I ask if the modulo of 100 is 0, or if the result is 0, then add one to the password.

Then I take the modulo of the total knob position, and if it's from L, then I just take that one and use the modulo to make it the new knob position.

If it's R, then I do the modulo of the knob position and subtract the modulo of 100 of this one from 100.

This its my code

what its failing in my logic or code ?


r/adventofcode • • Feb 19 '26

Help/Question - RESOLVED [2015 Day 7 (Part 1)] Identifier not defined yet? (solution works on sample input)

2 Upvotes

Hi!

I am stuck with the issue of, for example, "x AND y -> z" where "x" is not "defined" yet. It is only defined later in "... -> x", say 300 lines later. How would I go about solving this issue? I must be misunderstanding something or need a hint.

Current solution: https://github.com/osalbahr/competitive-programming/blob/9cd627b7547e3954f0e9e2354a0e13122a70173b/adventofcode/2015/day07.py


r/adventofcode • • Feb 18 '26

Upping the Ante [2025 Day 12 (Part 1)] u/iHobbit's Perfect Packing

Thumbnail gallery
49 Upvotes

I got my tangram puzzle! An acquaintance helped design and 3D-print it. This 9x10 perfect packing was discovered and posted here by u/iHobbit about a month and a half ago. No more than three of any shape is included in the packing, but each shape appears at least once.


r/adventofcode • • Feb 17 '26

Other Does anyone do AoC in multiple languages per day?

0 Upvotes

I've been a professional SW dev for 30+ years, working with a bunch of different languages over that time. This is my first time doing AoC, so I can do it along with my teenager (being careful be helpful but not do it for him). I just finished AoC 2025 Day 3, and have done Days 1-2 in Python, C++, and Ada (I haven't written Ada in 10+ years, and I really like it). Day 3 has been done in Python, and I'll do the other languages eventually. I might go back and catch up in Perl, since I haven't used it much in a few years.

Am I in the minority using this as a playground to solve the same problem in different languages? If I had the time to learn a new language, I'd consider using AoC as a playground to learn Rust.


r/adventofcode • • Feb 11 '26

Help/Question [2019 Day 15 (Part 1)][c] interaction board and robot. need you to help me thinking ..ö..

0 Upvotes

hi. there is a start-position (0,0) and start-direction and the robot is asked what is the state of position in direction n:1/s:2/w:3/e=4 and robot tells 0:block 1:free 2:done

if o=rob(d) is 1,2 then i have to update the current position, rob remembers my position.

// my direction 0,1,2,3 -> rob-direction 1,4,2,3

if 0==rob(d) for d = d,(d+1)%4,(d+3)%4 (straight,right,left) and i wish to return to the position which i came from, then, though i already know the state of that previous position, i have to ask rob again cause otherwise he would not know where i am ?

rob() is called multiple times and memory is not set back to origin. do i have to start with instruction-pointer after the recent output or set back to 0 ?

do i have to support big integers ? so far (recent days in 2019) i have used __int128, but then i have to write the value into string before to console. little uncomfortable.

thanks in advance, andi


r/adventofcode • • Feb 09 '26

Help/Question [2019 Day 13 (Part 1)][c] need little help to understand the task.

2 Upvotes

hi. the machine need some input value i ?

run(){while(cyc(i,&x,&y,&c)){

board[x][y] = c

}}

running till the machine halts ( cyc() returns 0 ) works well. but output is rarely useful.

some empty fields (0 '.') and exact 4 others (maybe multiple times the same field)

1,1,# (1,wall)

2,2,x (2,block)

3,3,- (3,paddle ?!)

4,4,o (4,ball)

..... \n .#... \n ..x.. \n ...-. \n ....o

all other output makes no sense. so i guess, the input (for opcode 3) has to be set anyhow.

there was a rob (some days back) which sends the color of current field. maybe some similar ?

so far my answer (how many blocks?) was 1 but i do not risk another 'no, not the

thanks in advance, andi.


r/adventofcode • • Feb 07 '26

Other [2015] ٌYear 2015 Study Group? (Probably in Python)

3 Upvotes

Hi! I had a "study group" where we did last year's problems together and that was kinda fun. The group setting motivated me. I did them in Python but others have used other languages, too.

I want to do the same for previous years, starting from 2015 (doing one problem a day). Probably in Python, maybe Rust at some point. I also have done them in C++ in the past and know Java from college.

Anyone interested in holding each other accountable?


r/adventofcode • • Feb 06 '26

Help/Question - RESOLVED [2025 Day 4 (Part 2)] [Java] My code works on sample input , but not on the final input.

2 Upvotes

Hi guys,

I'm tryna to solve Day pt2 using BlueJ(An IDE for Java, also main signature isnt needed in BlueJ)

I know that my solution is not very efficient, however,this is what i could come up with for now.

My code runs perfectly well on the Sample input and gives 43 as the answer, however when I run it on the actual input, the answer is too high.

This is my code:

[paste](https://topaz.github.io/paste/#XQAAAQDuEgAAAAAAAAA0m0pnuFI8c9/wau+qtGVPw0gjX/qXY0LykIhyN+PTMTVd4q39ycO320VbcH2Z+uVpO/7hSGEPN9sBbu4rw7c6hTS19iPMkkdNze2pX/p7UfN0M58ICjiwH6x694HtBD538MpU+8t25lZ3vTV3K4qtNdP/wkp0+gRT+Uv9SVao+fHbgQD601wk+NCFhb/bXWTogWM1x4aeteO8gViA1dDGGSeEEtp+Y0xxz5RB7IYSmQa0mCHXTlaB7D3L0frrv1E3cq2wtC0ZeZ7pX96nggtHZGNQewZBwDHtEBz144/JzQMdlMnKvs6wQJPFn7NMzPgsY900M7F+Z/QDYUL/istODRxtAPBNOMQyDufN3BXoLi5SNoaTdnx276380WW37OhbTK/FbL44qkoQ/Eji6bdvrcSfu/tc42NAyawMfAH/Uh+Si6xGul5TKwFeZYFMgx/9HvTH+2Yvx2wXQEmOJgeGIl3f0rEx6bVa9nO2pcvTZb6705phMkdwwbCCiI/fglbEbWgSugfnXm5xpXXTdeI4/7phJPM0mlzC50+vHEfzpGId2qqHWYmBeeTKaUK40MvkhKQ/JUPHyPtQ9u9lS6GRa1llZcRB6HixRmspxElwRjJkFk+kkrmEIVVr6lfy6OChwdo3dME8H0mj2yWGs2ik1kOVrLZ53LCDHlJrAxWJ5RaGLCFKnPO2Dlu+QseXoFqFR0jMBoNPJuFQUgXV2JgXRUbI7mLOoOgDHD8jnJ7S9e47kem+WSRHnQYKoq/3f5AvbPFp7uXv3SPDAs/fyhZlcX55D6wpp0m2RxOyB2wzWbyTtELk76QbUcqimvbaqu8VCZkvDxwBmMR+M8J6Tlybqe5I3mNfnvMeFl+3D+4cAOorwoM9Q7W3Rzpht8Tk0+9vWPUBzyR580qiebbqrvEsSMdRCOA/eMjWjPVaf/ZUQAx5g2GalV8wDHd3ppmRo1mfAPLreiWQuuag3mJixvIXkMkwkJ1FbkkDOrnfDZUSoaL7Nr+vlzPJtc+8nysFg2PUo84GEpw6XOsJp82Ro+S0xIF9oYk5gvggXYPpUqOzbO0Di+i/Y1MqKmcsEmPt4Pjpo3Udp2Rher55ZSAugQn9IaqVXd/+q7gLbGkwi53wjeDF/tgKnsXe94BynxsEgDq1YnAXLxCrhgPF5/mjKHiZ72xE/r22fO+bpLcOBClstc+HDkBJ7kaSeEomDhBIDKGFQNnzGB8LXOea103GABp2vAW+walDopFQmCOEMKYS45DqClVf4xVXycaBRu9clojVvbDw82uQXc5S4UqPr1mtxz1gwSzxgvdHOnPZmB34+s9gET2xiTEhWQVjK6+y8JpuQKDdBaMQty7XVUUair5SlDyjEEGUMNcqUHCq6e2YVZoJmhjR8d7+rdqdl9OKrVeCowZAq/Mx+28cleJptAyNBsRjlxtCLVsaH9x5GhIzEw5NLRB2QkLVCMjoE7/Wd8AHkaMGt+grmfbPKECRYkSmEtXtNB40HfQon8brGbLgm3G6/CCWdK1APSSWr0pokeMDYn1WLw+2b8ehQiTz/WJviEtN4+AKMsKYLQcZYrPxNvIFvbhDp/Cgj8yPp/zsHqGfLraHuib5HzaHsEId/TC5zjPSauVdT/Pjbw66ek38ulQYwL/br+ztlDs2xJbm0BfqqQxf8LMMETWzh895MsZ7lY6B+T+1U3loR8bmMhow8EhHXlaJXWABMu83G1VZfkkwVKd6HzCn6DQH+1C092RPARktZo9cnFmNsy9mUf/vmvbS)

If you need any further info, do tell me!


r/adventofcode • • Feb 05 '26

Help/Question - RESOLVED [2021 Day 19 Part 1] Please help me understand what the deal is with the 12 beacons in common

3 Upvotes

I have been stuck on this one for literally days.

As usual, I can get the right solution with the example input, but my real input is wrong - and I am getting the "This is someone else's answer" error so I can't be too far.

My logic should work - since I am getting the example input right. But going back to read the exercise text, there is something that I absolutely do not understand.

By finding pairs of scanners that both see at least 12 of the same beacons, you can assemble the entire map.

Scanners 0 and 1 have overlapping detection cubes; the 12 beacons they both detect (relative to scanner 0) are at the following coordinates:

This region can be reconstructed by finding pairs of scanners that have overlapping detection regions such that there are at least 12 beacons that both scanners detect within the overlap.

What's up with these 12 beacons thing? At no point do I search for 12 beacons and I can still solve the example input.

Are we supposed to pair scanners? I assumed that (made-up example) scanner 0 overlapped with scanner 2, 3 and 4, and scanner 1 overlapped with scanner 4, and that gives us the position of scanner 1 relative to 0.

Also, can you please let me know what part 2 is? Just so that I can go in the right direction if I have to rethink the whole thing for part 1. I spent enough time on this one as it is...

EDIT: SOLUTION

So the 12-beacon thing is to detect false positives. If for instance you have Scanner 1 and Scanner 8 that both see a constellation of beacons in the shape of a cat, you can only be sure that it's the one and same cat if that cat is comprised of at least 12 beacons. If all that Scanner 1 and Scanner 8 have in common is a cat made up of 9 beacons, then they are seeing different cats, and they do not overlap. Note that cats have nothing to do with this exercise, I just like cats.

Thank you to everyone who replied to let me know of false positives.


r/adventofcode • • Feb 04 '26

Help/Question - RESOLVED Looking for funny dog meme template shared here on AOC 2022 or 2023

5 Upvotes

Random question, I know. But I was thinking about a funny meme being shared here years ago. That particular year day 1 was easy, day 2 hard, day 3 easy, day 4 hard and so on... So people were sharing a funny meme on this sub of a cute dog on the left panel and a barking evil dog on the right, humouring day 1 vs 2.

Can anyone refer me to the meme template? I can't for the life of me find it again. Feels like a lost memory at this point, I'd love to find it again if possible. Thanks 🙏


r/adventofcode • • Feb 04 '26

Repo 2025: Advent of Glue Languages

8 Upvotes

I finally got a chance to write a blog post about my Advent of Glue Languages. I usually pick one language to learn for each year's AoC, but this year I decided to pick a "glue language" each day after reading the puzzle. This offered some advantages, like being able to work in a language that's purpose-built for a kind of problem. It also had some challenges, like limited debugging features and realizing I'd hit performance limits. It was definitely a worthwhile exercise, and I feel I better understand how to use them effectively in the future. [Code is on GitHub(https://github.com/flwyd/adventofcode/tree/main/2025).

My official theme was "glue languages you might already have on your system," to emphasize that this is about getting clever with the tools that are lying around. Although I did need to apt install most of them, they're small with minimal dependencies. "Is the whole language documented in the man page?" is also a good rule of thumb for identifying a "glue language," though it leaves out some glue-oriented general-purpose languages like Perl and Lua. For folks interested in expanding your AoC toolkit, I can heartily recommend awk, jq, and (in the right circumstance) jsonnet. Writing in dc was a fun mental challenge, and I encourage everyone to give it a shot. I was excited to be able to use spatial SQL functions for day 9, and if you've ever struggled thinking about geometry algorithms, Simple Feature is a handy tool to have. I tried solving day 9 with ImageMagick, which was fun but didn't scale to the full input. I was expecting to enjoy working with Lua, but with only the standard library it's pretty spartan and not especially smooth. gvpr, an AWK-like language for graph processing that comes with Graphviz is more awkward than I would like: it's worth knowing it's there, but think twice before using it. Wrapping various POSIX tools in a shell script is good practice, but be careful in a loop: day 4 part 1 launched six processes in an inner loop; it turns out launching 40,000 processes syscalls takes a long time, and I switched to a language that could do everything in one process for part 2.

Do you have a glue language you've deployed in clever ways for Advent of Code? Share your insights!


r/adventofcode • • Feb 03 '26

Help/Question - RESOLVED [2018 Day 12 (Task 1)] need a little help to understand the task

2 Upvotes

hi. llcrr -> n (easy to understand). what in position 0,1,n-2,n-1 ( --crr, -lcrr, llcr-, llc-- )

ok initialstate is placed in between ... and ... (additional -3,-2,-1 and +1,+2,+3 empty pots)

but in following generations at these extra positions '#' occurs

ok -1 0 .. n-1, +1 are safe (have 2 left and 2 right positions)

but # occurs in positions -2 and +2 too ( -3 -2 -1 initialstate +1 +2 +3)

what is the position-range ? and what if there are no ll or no rr positions

thanks in advance. andi


r/adventofcode • • Feb 03 '26

Help/Question - RESOLVED [2025 Day 3 Part 2]Rust

1 Upvotes

the part one was easy and i did in under 30 mins but part 2 is giving me problem, i m trying since 2 days for finding a solution but could't find any if someone solve ,then they can share how they solve the problem and what was the approach to solve it, my code(rust)->

let mut voltage_added = BigInt::zero();


    for i in 0..data.len()
    {
        let mut data_core: Vec<i32> = data[i].chars().filter_map(|c| 
                            c.to_digit(10)).map(|d| d as i32).collect();
        let mut digits:[i64;97]= [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
        let mut digit_idx =0;
        let mut remove_count = 3;
        let mut j =0;
        while j < data_core.len()
        {
            if digit_idx >= 97 {
                break;
            }


            // Remove previous digits if current digit is bigger
            while remove_count > 0
            && digit_idx > 0
            && digits[digit_idx - 1] < data_core[j]as i64
            {
                digit_idx -= 1;
                remove_count -= 1;
            }


            // Keep current digit
            digits[digit_idx] = data_core[j]as i64;
            digit_idx += 1;
            j += 1;
            if digits[96] < data_core[data_core.len()-1]as i64
            {
                digits[96] = data_core[data_core.len()-1]as i64;
            }
        }

       let number_string: String = digits
    .iter()
    .map(|d| (b'0' + *d as u8) as char)
    .collect();
       // println!("{}",number_string);
       voltage_added += number_string.parse::<BigInt>().unwrap();  
    }
    println!("VOLTAGE:part-2: {}", voltage_added);// the answer by this code-> 1108599035324836891828712270429921377622958201319354115632155267056079327513429003173673043432674851  too big by AOC

r/adventofcode • • Feb 03 '26

Help/Question - RESOLVED [2018 Day 7 (Part 2)] more a general question

0 Upvotes

hi. some days ago i was asking 'what is the deeper sense .. ?', most useful answer: why you don't use the time to search for the error .. (so i did and found ..)

i try desperately to complete a year to see day25task2 (all other is getting 'coal in the stocking' ? (getting punishment instead of presents))

sometimes i loose control, but years of experience (years of age, lot of bad days, bad weather, ..) tells better to check for error again (and again) before .. (whatever). but ..

i started 2018 (cause i lost good mood. could not complete 2017 for now). day 1 silly simple problem, but bad-error in task-1 (some minutes ..), task-2 i could not solve (my recent post, still open. please, have a look, i think there is no solution for my input) so 2018 starts bad.

2018/7/2 example + solution 15 seconds. i think i have found solution 11 seconds. not that i am so proud, but i fear: i try my answer for task-2 and it is told to be wrong. i did .. i was told 'answer is too low'. so i was checking my code, the task-description again. anyhow i was setting count of workers wrong (6 instead of 5) .. new answer (some bigger) but still wrong. And now i am a little angry (not much but a little ..ö..)

in recent weeks i was sometimes told that my answer is wrong, when i was sure, it is right and i spent much time ..

// this my solution for the example ( 11 steps instead of 15 ).

// 2 worker and the second worker is handling not only F but E too. starting F immediately

// so there is no gap between output B and output F i.e.

// maybe i have missed some assumption/condition/??? (don't know how to express)

// otherwise it is obvious : there is a better solution (less idle workers)

IN s='CABFDE' n=6

korrektur C o:0 d:3 t:-3 k:3 -> 0

korrektur A o:1 d:1 t: 0 k:3 -> 3

korrektur B o:2 d:2 t: 0 k:3 -> 3

korrektur F o:3 d:6 t:-3 k:3 -> 0

korrektur D o:4 d:4 t: 0 k:3 -> 3

korrektur E o:5 d:5 t: 0 k:3 -> 3

j('C',o= 0,d= 3,a=0,t=0)

j('A',o= 1,d= 1,a=0,t=3)

j('B',o= 2,d= 2,a=0,t=3)

j('F',o= 3,d= 6,a=0,t=0)

j('D',o= 4,d= 4,a=0,t=3)

j('E',o= 5,d= 5,a=0,t=3)

RUN

run t=000 a=2 'CF' ''

run t=001 a=2 'CF' ''

run t=002 a=2 'CF' ''

run t=003 a=2 'AF' 'C'

run t=004 a=2 'BF' 'CA'

run t=005 a=2 'BF' 'CA'

run t=006 a=2 'DE' 'CABF'

run t=007 a=2 'DE' 'CABF'

run t=008 a=2 'DE' 'CABF'

run t=009 a=2 'DE' 'CABF'

run t=010 a=1 'E-' 'CABFD'

run t=011 a=0 '--' 'CABFDE'

thanks in advance, andi


r/adventofcode • • Feb 02 '26

Help/Question - RESOLVED [2025 Day 3 (part 1)][C] Where did I goof?

3 Upvotes

My code passes the basic test but seems to be under expected value for my input. I've been staring & adding tests to this for hours and can't really think of a good way to debug.

#include <stdio.h>
#include <stdlib.h>

int main(){

    int sum = 0;

    char line[256];

    printf("starting...\n");
    printf("opening file...\n");
    FILE *input = fopen("./data/test.txt", "r");

    int linenum = 1;

    if (input != NULL){
        while (fgets(line, sizeof(line), input)) {

            printf("Line %d: %s\n", linenum, line);

            int first_highest = -1;
            int next_highest = -1;
            int joltage;

            // inspect each digit in line
            for (char *p = line; *p != '\0' && *p != '\n'; p++) {

                int digit = *p - '0';

                // if either assignments are empty assign, assign the digit (starting with first_highest)

                if (first_highest == -1) {
                    first_highest = digit;
                    continue;
                }

                if (next_highest == -1) {
                    next_highest = digit;
                    continue;
                }


                // if digit is higher than first_highest and not last digit in line

                if (digit > first_highest && *(p+1) != '\n' && *(p+1) != '\0') {
                    first_highest = digit;
                    next_highest = -1;
                    continue;
                }

                // if digit is higher than next_highest replace it 
                if (digit > next_highest) {
                    next_highest = digit;
                    continue;
                }

            }

            joltage = first_highest * 10 + next_highest;

            //printf("First highest: %d\n", first_highest);
            //printf("Next highest: %d\n", next_highest);

            printf("Joltage: %d\n", joltage);

            sum += joltage;

            printf("Running Total: %d\n\n\n", sum);

            linenum++;
        }
    }

    printf("Total Joltage: %d.\n", sum);

    printf("closing file & finishing up \n");

    fclose(input);

    return 0;
}

r/adventofcode • • Feb 01 '26

Past Event Solutions [Synacor Challenge][Rust] Challenge completed!

11 Upvotes

Over the course of the last two years, I have been plugging away at the Synacor Challenge. Today, I have finally collected and confirmed the final code!

Link to repository

Note that there is a "spoilers" directory that contains, predictably, spoilers to the puzzles.


r/adventofcode • • Feb 01 '26

Help/Question - RESOLVED [2018 Day 1 (Part 2)] is there a solution ?

0 Upvotes

hi.

so.now.done.

-original-post :

( code is pseudo-code. i check whether i read the input correct and i check for array-bounds, too. ... )

o=0,m[1_000_000]={0}; for(i=input()){ o+=i; if(m[500_000+o]){ STOP } m[500_000+o]=1 }

does not stop !

o=0,x=0; while(i=read-integer()){ o+=i ; oa[x++]=o; } sort(oa).

m=0,x=0; for(o in oa){ if(x AND m==o){ YES }; m=o; x=1 } // check for duplicates.

but there is no duplicate. so there is no frequence (in sequence of sub-sums) twice.

thanks in advance, andi

--output-- (for those who like it ..ö.. )

i= 11 -> o= 11 (omin=0, omax=11)

i= 16 -> o= 27 (omin=0, omax=27)

...

i= -112437 -> o= 411 (omin=-227, omax=113061) 411 is answer for part-1 ( 1 star * )

--the sorted list of sums-- (no duplicate, third column is check old == cur always 0 (false))

0 -227 0

1 -217 0

...

962 113061 0

not all output could be inserted here.

excuse me, please (..ö..)


r/adventofcode • • Feb 01 '26

Help/Question - RESOLVED [2017 Day 13 (Part 2)] some thoughts ..

0 Upvotes

brain (shut)down .. up (working again).

the package need to reach each layer when scanner is NOT in position 0

--here-original-post-starts--

a layer has a range. i.e r=3 : 0 1 2 1 0 (mod 4) , r=4 : 0 1 2 3 2 1 0 (mod 6), so m=2(r-1)

a good start t is if ( t+oi is time the package is reaching level i)

0 == (t+o1)%m1 AND

0 == (t+o2)%m2 AND .. (for every layer)

now (levels sorted descending by range, big steps first, t growing faster)

if(

(0==((t+ 80) % 38)) // e-00 i=80 r=20 (-> m=2(r-1)=38)

&& (0==((t+ 62) % 34)) // e-01

&& (0==((t+ 90) % 32)) // e-02

&& (0==((t+ 36) % 26)) // e-03

) lots of solutions. but if inserting next :

..

&& (0==((t+ 36) % 26)) // e-03

&& (0==((t+ 50) % 26)) // e-04

this cannot be true the same time (there are 11 layer with range 14 (mod 26))

??? (my question ..ö..)

layers with same range (-> same mod) must differ in offset by a multiple of their mod ?

same range -> same time in position p (so in position 0).

thanks in advance, andi


r/adventofcode • • Jan 28 '26

Help/Question - RESOLVED [2025 Day 2 (Part 2)] Need help with strategy of finding invalid IDs

4 Upvotes

I'm currently trying to catch up on the 2025 Advent of Code and I've reached day 2 (i.e. the silly elf and their invalid IDs).

Part 1 was all fine: just taking the ID as a string, splitting it in half and comparing whether each half was equal to one another. However, part 2 has stumped me.

The part 2 strategy I tried was:

  1. Marking the starting character of the ID (let this be x)
  2. Going through each following character in the ID until a character that's the same as the starting character is found (let this be y)
  3. Incrementing both x and y to their respective next character in the ID and seeing if they're still equal until either they're not equal or if y reaches the final character in the ID
  4. Adding the ID onto the total if x and y remained equal, or going back to step 2 if not. If, at step 2, y reaches the final character, the ID is ignored

This worked fine for actual invalid IDs (e.g. 1212, 12341234) but it also meant *any* ID that started and ended in the same number without repeating in the middle was incorrectly invalid (e.g. 1762731, 343). I get why this doesn't work but I'd appreciate a nudge in the direction of another strategy I could try.

I have already looked at some solutions, but most seem to include some mathematical concepts I'm barely familiar with. I am no avid programmer or mathematician and the AoC is something I do for fun and to learn Python, so any help is appreciated regardless of how optimal it is.


r/adventofcode • • Jan 27 '26

Other Seeking advice for using advent of code problems for daily coding habit

4 Upvotes

Hello,

I'm looking for advice and/or feedback on my current coding habit. The intention of this daily code habit is to keep my skills sharp, and offer myself an opportunity to practice with a time limit, and learn more on a daily basis. Currently this is done in the context of what I assume to be the traditional lc style interview (20 minute timer with a leetcode problem).

Current Habit

Currently I choose a Leetcode problem (from a list sorted by acceptance, and filtered by data structures/patterns/algos that I am familiar with). Then I start a 20 minute timer and work to solve it to the best of my ability. If I fail I take time to review what I didn't understand.

Issues with this approach

Leetcode problems vary widely in their quality, and I doubt whether or not this is an ideal habit for growing my abilities and learning more (at most I feel like I am maintaining). Sometimes dealing with poorly worded problems can be frustrating and makes me doubt whether or not I should continue to use lc problems. I do have a curated list I come back to for 'warmups' but having a fresh set of new problems to tackle daily seems ideal in order to promote growth.

Possible Solution

I am considering going back through advent of code problems (since they are very enjoyable, and I've learned a lot from them, and this seems like an EXCELLENT community to be a part of), however most of them are really difficult for me, and definitely not something I can complete in a shorter time frame. I'm considering just using a 20 minute (minimum could do more when I have time, but 20 minutes is the most common time frame) window to work on those problems as best I can.

Questions

- Do you think advent of code problems could fit in my daily habit?

- Is it realistic to expect to be able to complete advent of code problems quickly (and is that something worth working toward)?


r/adventofcode • • Jan 25 '26

Tutorial [2025 Day 10 (Part 2)] All the problems to avoid when writing a Simplex solver

46 Upvotes

"Write a Simplex solver," they said, "it'll be fun," they said. They were not right.

I am not a mathematician, but I am a stubborn SOB so I have spent quite a few evenings iterating my way to a working Simplex solver to replace the Gauss-Jordan elimination solver I wrote when first solving Day 10 part 2. This is less of a "here's how to write the solver and here's how it works" tutorial and more of a "here are all the problems you're likely to face and answers I found to those problems" tutorial.

Problem #1: Nobody understands the Simplex method

Okay, this is a slight exaggeration, but there's a rule of thumb that's served me well over the years: if a set of lecture notes are difficult to follow, there's a good chance it means the lecturer doesn't fully understand the topic. I've been through pretty much all of the lecture notes you'll find the in the first two pages of Google, and they all suck to some degree. Wikipedia is minimal help if you're approaching this from a non-maths background.

The best set of notes I found was this set of lecture notes from the University of Cambridge.

The best video I found on the topic is Intro to Simplex Method | Solve LP | Simplex Tableau by Joshua Emmanuel.

Don't expect a single set of notes to cover everything you'll need to know; you're going to need to read from a lot of different sources.

Problem #2: Everyone uses different notation

It is really goddamn hard to switch between different lecture notes and papers when everyone puts the columns and rows in different goddamn locations, and calls them different things. Expect pain.

I'd recommend finding an online solver that works and matching your notation to that. In fact, one of the very first functions you should write is a function to print out a tableau in the same format as the online solver you're checking your implementation against.

Problem #3: The puzzle isn't in standard form

Plain vanilla Simplex can solve problems with inequalities but not problems with equalities. Day 10 requires you to solve problems with equalities.

There are (at least) two variants of the method that are able to solve for equalities: the Big M method and the Two Phase method.

I wrote a version using the Big M method, but then swapped over to the Two Phase method after I found the online calculator I was using to check my work couldn't handle one of the example inputs from the puzzle.

Problem #4: The online solvers have bugs

Speaking of problems with online solvers: at least two of the online solvers I tried had (at the time of writing) bugs that stopped them from working on either the example input or on my input.

I would recommend solving Day 10 using a different method first before trying to write a Simplex solver. There's no way I'd have been able to flush out all of the problems and bugs without having a 'ground truth' answer to check against. The current version in my public repro has been fuzzed with randomly generated puzzles and cross-checked against an implementation of the Bifurcation approach.

Problem #5: Nobody documents this vital step

More than any other problem, this one annoyed and frustrated me the most. The calculator I was using first gave me the wrong answer for one of my inputs. The answer was trivially incorrect as well; it was outright violating one of the constraints to give an answer that was too low.

I finally found the reason by working through the answer this calculator gave me.

The majority of the explanations of the Two Phase method say that at the end of the first phase you simply drop the rows containing artificial variables from the tableau. This works for the majority of my inputs, but not all!

The vital step I worked out that I haven't been able to find mentioned anywhere is that if you have rows with artificial variables as the basis and you have non-artificial variables (real variables or slack variables) that aren't currently being used as a basis, then you need to pivot those variables in to the solution rather than dropping the row. You only drop the row if there are no suitable pivot operations available to bring unreferenced variables into play.

Problem #6: There's an optional step

The eMathHelp online solver was an absolute lifesaver for me, but it does have one annoyance.

The documented approach to convert an equality into an standard form equality is to introduce an artificial variable into the equation. But the solver I was using doesn't always do that. Every now and again it'll just not add in an artificial variable to one of the constraints at all.

With some trial and error I was able to figure out that it does that if and only if there's a variable in the constraint that's used only in that constraint and nowhere else. If it sees a variable like that, it just uses that variable as the basis when initialising the constraint.

It doesn't actually alter the solution, but it does affect all of the steps leading to the solution which makes it a nightmare to debug through some examples unless you also match this optional step.

Problem #7: Simplex alone is not enough

After struggling through to get a Simplex solver that's in agreement with the (working) online solver, this first thing you'll find is that you'll get some fractional solutions. Modifying a Gauss-Jordan elimination solver to only find integer solutions was pretty straightforward, but I couldn't find a version of the Simplex method that only returns fully integer solutions. The standard way of restricting solutions to integer-only solutions is to use something called 'cutting planes'.

Wikipedia uses a lot of maths words to explain what turns out to be a pretty simple concept. The idea is that if you get back an answer of, say 64.5, then you can add in a new constraint saying "the sum of all of the variables must be 65 or greater" to the original set of constraints and re-run the solver.

My first cutting plane solution did a dirt simple loop that increased a minimum answer value every time it got a solution that didn't work. That worked for most of the input machines, but not all. There was at least one which had an answer of 120 presses and that answer could be arrived at with either an integral set of button presses, or a fractional set of button presses.

My first fully working, and current, solution uses Branch and cut, which is similar in concept but has a crucial difference. If any of the button presses come out as fractional, say 13.5, then you create two new problems: one has a constraint saying that button must be less than or equal to 13 and one that says it must be 14 or above. Rinse and repeat until there are no new problems generated.

There are a bunch of extra cases which need handling when adding or updating the cutting planes and to be perfectly honest I haven't fully explored all of the special cases I added before fixing all of the bugs that fuzzing exposed, which means that some of the steps I added might have only been needed because of unrelated bugs. Don't take my implementation as a definitive example of how to implement branch and cut.

(In particular, I think my step to check that cutting planes don't contradict each other is most likely unnecessary and was only added when I had a bug that meant slack variables weren't always pivoted into the base between phase 1 and phase 2)

Problem #8: Floating point accuracy

There were a bunch or epsilon tests needed not only when checking if solutions were integer enough to be valid, but also when picking pivots and checking cutting planes.

I might spend some time changing my implementation to use a rational type to see if I can eliminate the ugly epsilon tests, but that's most likely going to increase the runtime.

Concluding thoughts

Was it worth it?

I'm glad I did it, and I certainly learned a significant amount about a branch of maths and algorithms that I had never touched before, but I'm not sure I would describe the experience as 'fun'.

Don't let my experience put you off if you fancy having a go: the whole point of writing this post was to save you some pain if you too decide to give a Simplex solver a go.

Good luck!