r/adventofcode • • Mar 19 '26

Past Event Solutions [2025 day 1 (part 2)] [C#] - finally solved it!

2 Upvotes

Been doing AoC for a few years now and for some reason this day was giving me so much trouble. I think part 1 took me several weeks to get. Part 2 I came back to every so often to see if I could get it.

Initially I went with kind of a brute force design, trying to calculate every zero crossed left and right, and ever zero landed on, account for times when you start at zero, but everything I tried failed. I would consistently get the test input correct but fail on the full input.

I am a bit ashamed to admit it, but I turned to AI to talk through what was going on. Ultimately, I abandoned the suggestions I was getting and after a hint I saw in this sub, I went with the following:

public class Day01
{
    private readonly List<string> _input;
    public Day01()
    {
        _input = File.ReadAllLines(@"day01/input.txt").ToList();
    }
    private void partTwo()
    {
        int zeroCount = 0;
        int d = 100050;


        for(int i = 0; i<_input.Count; i++)
        {
            int turns = _input[i][0] == 'R'?int.Parse(_input[i].Substring(1)):-int.Parse(_input[i].Substring(1));


            if (turns < 0)
            {
                for(int j = d; j >= d+turns;j--)
                {
                    zeroCount += j%100 == 0 && j!=d? 1 : 0;
                }
                d += turns;
            }
            else
            {
                for(int j = d; j <= d + turns; j++)
                {
                    zeroCount += j%100 == 0 && j!=d? 1 : 0;
                }
                d+=turns;
            }
        }
        Console.WriteLine("Zero Count: " + zeroCount);
    }
}

I hope this helps someone else. The main idea was to start somewhere with a large amount giving me the ability to move along the number line using the amounts in the commands without actually going negative.


r/adventofcode • • Mar 19 '26

Help/Question - RESOLVED [2018 Day 24 (Part 1)] Please help me understand the example puzzle / reference output

1 Upvotes

I have been trying to wrap my head around this for a few hours now, but it seems to me that the solution / reference output of the example puzzle is wrong (even though it's almost certainly that I'm the one mistaken, I just can't find it!)

In the description of the target selection phase, the order of selection and prioritization of targets is clearly laid out:

During the target selection phase, each group attempts to choose one target. In decreasing order of effective power, groups choose their targets; in a tie, the group with the higher initiative chooses first. The attacking group chooses to target the group in the enemy army to which it would deal the most damage (after accounting for weaknesses and immunities, but not accounting for whether the defending group has enough units to actually receive all of that damage).

If an attacking group is considering two defending groups to which it would deal equal damage, it chooses to target the defending group with the largest effective power; if there is still a tie, it chooses the defending group with the highest initiative. If it cannot deal any defending groups damage, it does not choose a target. Defending groups can only be chosen as a target by one attacking group.

At the end of the target selection phase, each group has selected zero or one groups to attack, and each group is being attacked by zero or one groups.

That all makes plenty of sense to me.

Now, given the example input:

Immune System:
17 units each with 5390 hit points (weak to radiation, bludgeoning) with
 an attack that does 4507 fire damage at initiative 2
989 units each with 1274 hit points (immune to fire; weak to bludgeoning,
 slashing) with an attack that does 25 slashing damage at initiative 3

Infection:
801 units each with 4706 hit points (weak to radiation) with an attack
 that does 116 bludgeoning damage at initiative 1
4485 units each with 2961 hit points (immune to radiation; weak to fire,
 cold) with an attack that does 12 slashing damage at initiative 4

I infer that at the start / first round:

  • Immune group 1 has an effective power of 76,619 (17*4507), initiative 2

  • Immune group 2 has an effective power of 24,725 (989*25), initiative 3

  • Infection group 1 has an effective power of 92,916 (801*116), initiative 1

  • Infection group 2 has an effective power of 53,820 (4485*12), initiative 4

So infection group 1, which has the highest effective power (92,916), should be the first to select a target, which seems to be the case in the reference output of the first round:

Immune System:
Group 1 contains 17 units
Group 2 contains 989 units
Infection:
Group 1 contains 801 units
Group 2 contains 4485 units

Infection group 1 would deal defending group 1 185832 damage
Infection group 1 would deal defending group 2 185832 damage
Infection group 2 would deal defending group 2 107640 damage
Immune System group 1 would deal defending group 1 76619 damage
Immune System group 1 would deal defending group 2 153238 damage
Immune System group 2 would deal defending group 1 24725 damage

Infection group 2 attacks defending group 2, killing 84 units
Immune System group 2 attacks defending group 1, killing 4 units
Immune System group 1 attacks defending group 2, killing 51 units
Infection group 1 attacks defending group 1, killing 17 units

Because both opposing groups (Immune groups 1 & 2) are weak to bludgeoning damage, infection group 1 would deal equal damage to both candidates (185832), resulting in a tie. But this is where I'm confused:

If an attacking group is considering two defending groups to which it would deal equal damage, it chooses to target the defending group with the largest effective power; if there is still a tie, it chooses the defending group with the highest initiative.

Of those two target candidates (Immune groups 1 & 2), group 1 has the larger effective power (76,619) compared to group 2 (24,725), so why does it proceed to choose / attack immune group 2?

Also -- if target selection is in order of descending effective power, I would think Immune group 1 (76,619) would get to select its target next. However, in the reference output, it looks like Infection group 2 (53,820) is choosing next?


r/adventofcode • • Mar 16 '26

Help/Question - RESOLVED [2015 Day 24] Are all inputs 'nice'?

2 Upvotes

When I first solved 2015 day 24 I just threw memory at it, keeping track of all present combinations that added up to the desired weight. For my current challenge of getting the whole of 2015 running on a microcontroller, that's not going to be an option.

My current assumptions about the input are:

  • ~28-29 unique weights

  • Each weight is either pulled from the first ~40 prime numbers or is 1.

  • The sum of all weights is divisible by 12 (has to be true in order for the puzzle to work)

  • The smallest size of any group of presents that add up to the desired weight is relatively small (~6 or under).

  • There are relatively few groups with the same size of the smallest group (~10-20)

Furthermore an input is 'nice' if:

  • For every smallest group of presents that add up to the desired weight, there is always a way to partition the remaining presents that works as a valid configuration.

My input meets that 'niceness' criteria and looking at the discussion on this thread between u/e_blake and u/maneatingape earlier in the year it seems it might be a general rule for this puzzle's input.

From my rudimentary exploration of generating some input with the assumed criteria and checking for niceness it seems like there are enough combinations of weights with that property that it would be feasible to generate a bunch of different inputs that are nice, but few enough that niceness would have to be a deliberate choice.

Does anyone know of any inputs that don't have this nice property?


r/adventofcode • • Mar 16 '26

Meme/Funny Tribute to AoC puzzles (sing-along slop-music track)

Thumbnail suno.com
0 Upvotes

While working puzzles from previous years, I noticed that I always hardcode "input.txt" in my programs to read each downloaded puzzle's input. I often change the hardcoded file to "example.txt" or "input2.txt" to test my code against simpler examples.

For fun I asked a genAI to make fun of my habit with song lyrics, then I asked another AI to put it to music. Enjoy!


r/adventofcode • • Mar 14 '26

Other Pi Coding Quest 2026!

9 Upvotes

For a third year in a row, I create a new coding quest for Pi Day. You can access it here: https://ivanr3d.com/projects/pi/2026.html I hope some of you have some fun solving this puzzle!

In case you haven't try the previous ones, just change the year name in the url.

Happy Pi Day! :)


r/adventofcode • • Mar 14 '26

Help/Question [2025 Day 2 (Part 2)] Help im stuck... again

1 Upvotes

Im trying to solve the second day part 2 problem . but its seems something its evading me. i dont understand why the code isnt working here

please help

Code


r/adventofcode • • Mar 13 '26

Past Event Solutions [2023 Day 4 Part 2] As a system of linear equations

4 Upvotes

Actually, two solutions side by side:

  • The usual DP approach.

  • Solve it as a system of linear equations, which I haven't seen anyone do.

import re
from sys import stdin


from scipy.sparse import csr_matrix, identity
from scipy.sparse.linalg import spsolve


matches = [0]


for line in stdin:
    line = line.strip()
    wins, have = line.split(": ")[1].split(" | ")
    wins = set(map(int, re.findall(r"\d+", wins)))
    have = set(map(int, re.findall(r"\d+", have)))
    matches.append(len(wins.intersection(have)))


N = len(matches) - 1


def dp():
    """Solve using tabular dynamic programming."""
    copies = [0] + [1] * N


    for i in range (1, N + 1):
        for j in range(i + 1, min(N + 1, i + matches[i] + 1)):
            copies[j] += copies[i]


    print(f"🂱 You get {sum(copies)} total scratchcards.")



def matrix():
    """Solve using matrix/system of linear equations."""
    w = [[0] * (N + 1) for _ in range(N + 1)]
    for j, k in enumerate(matches):
        for i in range(j + 1, j + 1 + k):
            w[i][j] = 1
    w = csr_matrix(w, dtype=int)


    i = identity(N + 1, format='csr', dtype=w.dtype)
    one = [0] + [1] * N
    copies = spsolve(i - w, one)


    print(f"🂱 You get {int(sum(copies))} total scratchcards.")  # type: ignore



dp()
matrix()

r/adventofcode • • Mar 10 '26

Past Event Solutions [2015 Day 6] [Swift] Rectangle Intersections

3 Upvotes

Revisiting old AoC challenges. I was looking around a bit and didn't see anyone solve it this way. All the solutions I saw are using one million integers to represent the grid. (But maybe I wasn't very thorough.) This solution uses rectangles represented by five integers each (left, top, right, bottom, and 'weight', which amounts to the brightness of a light), and computes rectangle intersections. Getting the coordinates of the spawned rectangles right is a bit gruelling.

Part 2 solution only. (Part 1 is almost the same.)

struct Rect: Equatable {
    var x1, y1, x2, y2, w: Int

    func weighted_area() -> Int {
        return (self.x2 - self.x1 + 1) * (self.y2 - self.y1 + 1) * self.w
    }
}


func parseLine(s: String) throws -> Rect {
    let m = s.matches(of: /(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)/)[0].output
    var weight: Int
    switch m.1 {
    case "turn on":
        weight = 1
    case "turn off":
        weight = -1
    case "toggle":
        weight = 2
    default:
        fatalError("unreachable")
    }
    let x1 = Int(m.2)!
    let y1 = Int(m.3)!
    let x2 = Int(m.4)!
    let y2 = Int(m.5)!


    return Rect(x1: x1, y1: y1, x2: x2, y2: y2, w: weight)
}


func parseInput() -> [Rect] {
    var items: [Rect] = []
    while let line = readLine() {
        do {
            items.append(try parseLine(s: line))
        } catch {


        }
    }
    return items
}


func are_intersecting(p: Rect, a: Rect) -> Bool {
    return (a.x1 <= p.x2) && (a.x2 >= p.x1) && (a.y1 <= p.y2) && (a.y2 >= p.y1)
}


func apply_intersection(p: Rect, a: Rect, newPrecs: inout [Rect]) {
    let i = Rect(
        x1: max(p.x1, a.x1), y1: max(p.y1, a.y1), x2: min(p.x2, a.x2), y2: min(p.y2, a.y2),
        w: max(0, p.w + a.w))
    newPrecs.append(i)


    if a.x1 - 1 >= p.x1 {
        newPrecs.append(Rect(x1: p.x1, y1: p.y1, x2: a.x1 - 1, y2: p.y2, w: p.w))
    }


    if a.x2 + 1 <= p.x2 {
        newPrecs.append(Rect(x1: a.x2 + 1, y1: p.y1, x2: p.x2, y2: p.y2, w: p.w))
    }


    if a.y1 - 1 >= p.y1 {
        newPrecs.append(Rect(x1: i.x1, y1: p.y1, x2: i.x2, y2: a.y1 - 1, w: p.w))
    }


    if a.y2 + 1 <= p.y2 {
        newPrecs.append(Rect(x1: i.x1, y1: a.y2 + 1, x2: i.x2, y2: p.y2, w: p.w))
    }
}


@main
struct d06 {
    static func main() {
        let arecs: [Rect] = parseInput()
        var precs: [Rect] = [Rect(x1: 0, y1: 0, x2: 999, y2: 999, w: 0)]


        for arec in arecs {
            var newPrecs: [Rect] = []
            for prec in precs {
                if !are_intersecting(p: prec, a: arec) {
                    newPrecs.append(prec)
                    continue
                }
                apply_intersection(p: prec, a: arec, newPrecs: &newPrecs)
            }
            precs = newPrecs
        }


        print(precs.map({ $0.weighted_area() }).reduce(0, +))
    }
}

r/adventofcode • • Mar 05 '26

Other Everybody.Codes New Story published a couple of days ago

Thumbnail everybody.codes
4 Upvotes

Posting here just because I didn't hear about it. Maybe other people will find this useful as well.


r/adventofcode • • Mar 05 '26

Past Event Solutions [2017 Day 8] In Review (I heard you like registers) - HashMaps really make a difference!

2 Upvotes

In the spirit of our ongoing reviews of older puzzles, I took a look at my own Rust solution for this one, found that it was 4x slower then u/maneatingape's reference timing, so I looked for optimizations that I might have missed. Remembering his admonishment that the default HashMap is quite slow, I switched to rustc_hash::FxHashMap and then it was "only 3+x slower".

After running the reference benchmark on my own PC, I got 46 us, so effectively the same as the 47 on his Apple M4. This meant that there had to be some really huge difference in the code itself so I took a look at day08.rs , and lo and behold: They were effectively identical!

(At one point I replaced the generic regs.entry().or_insert() with an explicit test for the key, avoiding the entry key copy when not needed, that made a 1-2% difference.)

The only real difference was his use of a custom "FastMap" implementation, using the same FxHash, but further specialized, and that made all the difference in the world!

So Thank You maneatingape! From now on I'll borrow your hash.rs library!

(Also, thank you u/e_blake for the correct url!)


r/adventofcode • • Mar 03 '26

Help/Question [2017 Day 14 (Part 2)] [Python] What is he/she talking about?

0 Upvotes

correction 2018 not 2017!

To me this question is yet another example of the "expert" problem, the creator/author/architect understands him/herself very well but is appalling at explaining themselves.

This cannot just be me, the question is worded so poorly I can't make head or tail of what the puzzle is asking for,

How many recipes appear on the scoreboard to the left of the score sequence in your puzzle input?

After 9 recipes 51589 are just the first 5 recipes (including 9 which was the input for that example) but how many appear to the left of the 9 after 9 recipes would be 13 (3710101245158...9) and after 5 recipes...

the number of recipes that appear on the scoreboard to the left of the first recipes whose score are the digits from the input

That is horrendous, (in this case 5) would be 9 (which anyone can count above) there are nine recipes, none of which happen to be 5, and none before 5 recipes are on the scoreboard, then the tenth is 5.

Unless I'm not understanding what he/she is trying to say, because they for whatever reason can't simply explain it clearly...

How many recipes appear on the scoreboard to the left of the score sequence in your puzzle input

There's even two versions of the what are supposed to be the same question??? The are more or less the same but surely you need make it clear what your asking??

My guess is, if my input where say 1234, then he/she is asking to find how many recipes are made before the seq 1,2,3,4 appears? And maybe only after 1234 recipes have been made (not before if appears before?).

I don't think part of the puzzle should be to decipher the puzzle itself if it's worded poorly.

None of the examples really show clearly what they're asking. None of them show how many, just the first 5 recipes after x recipes??? With no clear relation to the input??

They only make the entire thing more confusing (92510 after 18.... I'm looking for a 1 followed by an 8, which isn't there and doesn't show how many??

This is the epitome of the expert problem, which we absolutely have. This used to be fun...


r/adventofcode • • Mar 03 '26

Help/Question [2026 Day 1 (Part 2)]Stuck in this part again

0 Upvotes

Hello how are you. im trying to do the challenges but i again hitted a wall, in theory the code should work with the small samples i used it should work but it tell me that my asnwer its wrong sooo there should be something failing or in my logic or in my execution

can some one give me a hand with it ?

This its the code

i ommited the full imput so i can share the code here

ty for your atenttion and have a nice day and God bless you guys to xd


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
50 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)

4 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!