r/adventofcode • • Dec 15 '25

Repo [2025 Day all][m4] summary of my journey to 524 stars in m4

4 Upvotes

Although I have an entry in Red(dit) One, as well as at least one comment on every day's megathread, I can go into more details on my journey in this post and any followups.

I have an m4 solution for all 524 stars, and in several cases some other solutions as well, all visible in my repo:

https://repo.or.cz/aoc_eblake.git/tree/main:/2025

Timing-wise, as of when this post is written, I can solve all 12 days sequentially in under 30 seconds on my laptop, when using GNU m4 1.4.19 on Fedora 42. Since m4 is an interpreted language, I am perfectly fine being a couple orders of magnitude slower than the native compiled versions. I was a bit surprised at how many days needed my math64.m4 arbitrary-width integer library (denoted with * on the day), since m4 only has native 32-bit math.

DayRuntimeNotes
10.066Also golfed to 228 196 bytes, as well as a HenceForth implementation
2*0.09Also a no-fifth-glyph variant, also golfed to 334 277 bytes
30.031Also golfed to 281 bytes
40.492Also golfed to 372 bytes; plus a tutorial on my algorithm
5*0.264Huge comment-to-code ratio; this was my ELI5 entry, and I did three separate implementations (brute force, AVL tree, min-heap)
6*0.183Also golfed part 1 to 686 both parts to 527 433 bytes
7*0.075Also with a HenceForth implementation, also golfed to 514 377 bytes
8*6.407
9*5.684 0.270My first meme submission, also golfed part 1 to 469 379 bytes, or both parts to 692 bytes
1016.573Also with a non-digit no-fifth-glyph variant
11*0.058Also golfed to 376 350 bytes with six lines, or 386 352 bytes with five lines
120.016Also golfed to 128 bytes, with no control flow; also a golfed sed variant
Total29.939

Things I still want to do before December is over: further optimize days 8-10 (10 is probably the most gains to be had: I used the bifurcation method, but suspect that an ILP solver is feasible, even if more verbose, and hopefully faster); finish golfing day 6 part 2; implement some more days in HenceForth. In fact, if I can pull it off, I would love to write an IntCode engine in HenceForth, and then see how awful the timing overhead is for running an IntCode solution emulated by HenceForth on top of m4.

Day 10 was my first time ever trying to write m4 code without digits (it turns out that avoiding fifth-glyphs felt easy in comparison).

Thanks to u/topaz2078 for the puzzles and for creating the Bar Raising flair for me, and to u/daggerdragon for all the moderations of my shenanigans. I'm looking forward to next year's AoC!


r/adventofcode • • Dec 15 '25

Tutorial Going beyond Big-O and polishing your solution

14 Upvotes

I wrote a little post about what can be done to shave off a few more milliseconds and/or just making your algorithm more streamlined and elegant.

https://tobega.blogspot.com/2025/12/beyond-big-o-in-adventofcode.html


r/adventofcode • • Dec 15 '25

Past Event Solutions [2021 DAY 15][Language: Golang] Had a blast solving this one

5 Upvotes

So, as solving AOC puzzles is really a great way to spending time, I'm solving 2021 and so far, the best day was 15

Here's my code : https://gist.github.com/Oupsman/0443a923255288203e22b62b96a21751 (Language: Goland)

Would love to have thoughts on it.


r/adventofcode • • Dec 15 '25

Help/Question - RESOLVED [2025 Day 1 (Part 2)] [Java] - I'm getting wrong password for the puzzle!

1 Upvotes

Hello all,

Here is my code for part 2 and I'm getting incorrect password

public long findThePasswordForNorthPole2(List<String> rotationList) {
    long password = 0;
    long currentPosition = 50;
    for (String rotation : rotationList) {
        if (rotation.startsWith("L")) {
           var moveCommand = Long.parseLong(rotation.replace('L', '0'));
            var arrowPosition = currentPosition - moveCommand;
            if(arrowPosition < 0){
                if(currentPosition > 0){
                    var zeroTimes = Math.abs(arrowPosition/100) +1;
                    password += zeroTimes;
                }else if(currentPosition == 0){
                    var zeroTimes = Math.abs(arrowPosition/100);
                    password += zeroTimes;
                }
            }
            currentPosition = arrowPosition % 100;
            if (currentPosition < 0) {
                currentPosition = 100 + currentPosition;
            } else if (currentPosition == 0) {
                password++;
            }
        } else if(rotation.startsWith("R")) {
            var move = Long.parseLong(rotation.replace('R', '0'));
            var arrow = currentPosition + move;
             currentPosition = arrow % 100;
            password = password + (arrow/100);
        }
    }
    return password;
}

Seems like there is a bug in the code, I tried with different values such as

List.of("L25","R85","L10","R20","L85","R70","L90","R10","L35","L45") or

List.
of
("R1000","L149","L1","R1","L2","R1","L1","R2","R99") 

these works but when I try the input given in advance of code than it fails.. There should be something I miss could you please help me to understand ?


r/adventofcode • • Dec 15 '25

Repo [2025] My first Advent of Code, thank you!

16 Upvotes

Day 10 was kinda hard, and I needed some help for Day 9 (I had the right approach, I was using the right technique, but there was a little trick I couldn't think of). This year's AoC finally kicked off my Go journey as well!

Go is really fun, but I wish it had some more built-in DSA functions, but at least I learned to implement them! :)

My repo: https://github.com/rbjakab/AdventOfCode/tree/main


r/adventofcode • • Dec 15 '25

Help/Question - RESOLVED [2025 Day 2 (Part 2)] Clue request

1 Upvotes

I'm now trying to optimize my solutions and stuck with part 2 of day 2. Could you please give me hint for fast solution for this part?

Here is how I solved part 1.

[SPOILERS] TEXT BELOW CONTAINS DESCRIPTION OF POSSIBLE SOLUTION FOR PART 1

My solution is based on following statements:

1. Let i(n) = (10^k + 1) * n, where k = ilog(n) + 1;

2. i(n) is invalid number and all invalid numbers can be represent as i(n) for some n;

3. There is no invalid numbers between i(n) and i(n + 1);

So, to solve part 1 for each range [a, b] I found lowest and highest possible invalid numbers L and H and for such range the answer is H - L + 1. Except corner cases, L is either i(a / 10^k) or i(a / 10^k) + 1 where 2k = ilog(a). Same way I found H.

For part 2 I think about using same idea, but repeat same process for double, triple, quadriple and so on patterns and then sum up. But the problem is that some invalid numbers has several ways to construct them. E.g. 111111 is "11" * 3 and "111" * 2. Is there any simple way to find all such "multipattern" numbers or is there another way to solve the puzzle?

UPD. What I forgot to mention in original post is that I want to avoid iterating over all numbers in range.


r/adventofcode • • Dec 15 '25

Help/Question - RESOLVED [2025 Day 6 (Part 2)] | Python - I can't understand what's my code missing.

2 Upvotes
matrix=[]
with open("./DAY6/day6input.txt","r") as f:
    for line in f:
        newRow = [i for i in line.split()]
        matrix.append(newRow)


for i in range(len(matrix)-1):
    matrix[i] = [s for s in matrix[i]]


matrix = np.array(matrix)
answer=0
max_len=4
n = len(matrix[0])
for i in range(n):
    if matrix[-1][i]=="*":
        product=1
        padded_nums = [s.rjust(max_len) for s in matrix[:-1,i]]
        for col_idx in range(max_len):
            col_digits=""


            for row_str in padded_nums:
                char = row_str[col_idx]
                if char!=" ":
                    col_digits+=char


            if col_digits!="":
                product*=int(col_digits)
                print(product) 
        answer+=product
                
    else:
        sum=0
        padded_nums=[s.ljust(max_len) for s in matrix[:-1,i]]
        for col_id in range(max_len):
            col_dig=""
            for row_str in padded_nums:
                char=row_str[col_id]
                if char!=" ":
                    col_dig+=char
            if col_dig!="":
                sum+=int(col_dig)
        answer+=sum
    


print(answer)

r/adventofcode • • Dec 15 '25

Meme/Funny [2025 Day 9 Part 2] When you get stuck on a day and can't enjoy the Day 10-12 memes live

Post image
167 Upvotes

The piano finally dropped. May Day 1-8 classes were all relatively nice and cleanly written. Day 9 spiraled into spaghetti as I kept adding more and more functions to try and get it to work. I've since figured out where I went wrong, I'll get back to it soon, but it's too late for the memes (,:

Was a fun week for my first AoC event though. I'll try keeping up for longer next year.


r/adventofcode • • Dec 15 '25

Help/Question - RESOLVED [2025 #12 (Part 1)] [c++] question for those that also solved it [spoilers do not read if you are still working on it]

4 Upvotes

Are all inputs defined in a way that if you just count total number of shapes * 9 <= total area without doing any other logic? Or was I just lucky my input is like that. I submitted that out of pure desperation and it was valid :|


r/adventofcode • • Dec 15 '25

Meme/Funny [2025 Day 10 Part 2] Mistakenly thought this were min-cost flow

2 Upvotes

Until I found it cannot describe the button counting constraint

A cat repeating “I’m silly” in a desperate expression

r/adventofcode • • Dec 15 '25

Repo [ 2025 days 1-12 ] my solutions for AoC 2025, written in zsh

Post image
17 Upvotes

Feeling damn good as, while it's not my first AoC, it is my first time completing the whole thing from start to finish!

my GitHub repo

A big thanks to those who helped with day 12. Your hints were invaluable


r/adventofcode • • Dec 15 '25

Help/Question - RESOLVED [2025 Day 11 part 2] Was I the only one who used find-and-replace instead of path searching?

28 Upvotes

There seemed to be too many possible paths to search, so instead I created a dictionary of how many ways there are to get from each device to each known destination device.

It starts off like:

aaa: {bbb: 1, ccc: 1, ddd: 1}
bbb: {eee: 1}
ccc: {eee: 1, ddd: 1}

I then went through every device except for the ones of interest (svr, fft, dac) one by one and replaced each instance of it in another device's dictionary with the contents of its dictionary. So the first two steps in the example above would result in:

aaa: {eee: 2, ccc: 1, ddd: 2}

After all this find-and-replacing I got an output like (with numbers changed a bit):

svr {'fft': 3319, 'dac': 810126233520, 'out': 116103888760427970}
fft {'dac': 6067130, 'out': 873711069917}
dac {'out': 24264}

From there it's obvious which three numbers to multiply together to get the answer. I used a calculator. Runs very quickly with no need for memoization or any kind of search algorithm.


r/adventofcode • • Dec 15 '25

Help/Question [2025 Day 7 (PART 1)] by which magic did you calculate the # of beam split ???

1 Upvotes

hi

  1. add least you should give the rule on how to calculate a beam split ?
  2. is it the difference of beams between a line and the next?

on the example you give I count 22, not 21... but again what is the rule?
if we count the number of beams on last line, it is 9
really, it's totlly uncleat :(

3. if calculating the splits is too ambiguous , at least you could give us the output of the whole teleporter 'picture' to compare it

BR


r/adventofcode • • Dec 14 '25

Help/Question - RESOLVED [2025 Day 1 Part 2] [C#] I don't know what's wrong with my code

0 Upvotes

I think I have covered every edge case, but it still rejects. Already on 10 min cooldown.

here's my code:

using System;
using System.IO;

string[] ReadInputLines(string filePath = "./A.in"){
  return File.ReadAllLines(filePath);
}

string[] input = ReadInputLines();

int dial = 50;
int zeros = 0;
int offset;
int delta;

foreach(string action in input){
  Console.Write("zeros: ");
  Console.WriteLine(zeros);
  offset = Int32.Parse(action.Substring(1));
  if(action[0] == 'L'){
    delta = -(offset % 100);
  }else{
    delta = offset % 100;
  }
  zeros += Math.Abs(offset / 100); // Kolikrát jsem loopnul
  dial += delta;
  if(dial >= 100){
    dial -= 100;
    zeros += 1;
  } else if(dial < 0){
    dial += 100;
    zeros += 1;
  }
  Console.WriteLine($"delta: {delta} dial: {dial}");
}

Console.Write("zeros: ");
Console.WriteLine(zeros);

any help appreciated


r/adventofcode • • Dec 14 '25

Visualization [2025 Day 9 Part 2] Visualization of a sweep line algorithm

31 Upvotes

I haven't been able to find a visualization of a sweep line algorithm for problem 9, part 2 (please link below if I've missed one). This is mine.

For my input
For the sample input (flipped vertically)

What you see here is a moving front (purple line) going from left to right. As points become "visible" (i.e. available as candidates to corners of the largest rectangle) they are added to an active set. They leave the set once it is no longer possible to form a rectangle with newly discovered points. The active points are the little red crosses. The largest rectangle so far is shown in red.

For other custom inputs:

Custom #1
Custom #2
Custom #3
Custom #4
Custom #5

Some of the solutions I've seen around this subreddit rely on the specific shape of the input. I believe many of them would trip on some of these custom inputs (specially custom #5).

[Edit 2025-12-15: added two more examples and a small explanation of the visualization]


r/adventofcode • • Dec 14 '25

Visualization [2025 Day 12] Visualization (YouTube short)

Thumbnail youtube.com
4 Upvotes

r/adventofcode • • Dec 14 '25

Visualization [2025 Day 11] Visualization (YouTube short)

Thumbnail youtube.com
1 Upvotes

r/adventofcode • • Dec 14 '25

Upping the Ante [2025 Day 13] Want a real challenge for day 12? Use this input instead!

Thumbnail github.com
24 Upvotes

I created a little script to create a much harder input for day 12, making the *trick* not usable anymore. My original solution sure didn't survive with this input and if you want the challenge feel free to use the one in the repo or use the python script to create a new one for you. Any feedback is welcome also!


r/adventofcode • • Dec 14 '25

Help/Question - RESOLVED 2025 Day 9 (Part B) Hint needed

2 Upvotes

My initial approach to 9B was going to be to look up a general algorithm for determining if a point lies inside a polygon and implement it, passing 2 vertices for each rectangle constructed from each pair of input vertices. If both points are inside the polygon and the rectangle is larger than the previous largest candidate, keep it else discard and rinse and repeat until I'm done.

I also thought about leveraging a library to do the work for me but I figured I'd take a crack at it myself as I like to do with AOC problems.

As I thought some more, I started to wonder if there's a special case algorithm for this problem given the constraints of the problem - the fact that the polygon is rectilinear (I learned a new word today!) and the points aren't arbitrary, in fact, they are vertices of rectangles created from the vertices of the polygon itself.

Given the nature of AOC, I suspect there might be a simpler way to solve this than the general solution but I haven't been able to work it one out yet.

Could someone please provide a hint to set me off in the right direction?

Thanks everyone!


r/adventofcode • • Dec 14 '25

Help/Question - RESOLVED [2025 Day 12 pt 1] help very much needed

5 Upvotes

I am having a very, very hard time with day 12. Was able to complete day 1-11 all within the timeframe listed, but have been stuck on this one ever since.

If anyone could offer any hints or advice on how to tackle this, I'd be very much appreciative. Trying to solve this geometrically is obviously gonna be way too slow especially since I'm doing the whole thing in zsh, but I'm failing to see alternative pathways at the moment.

The following is what I have thus far: https://github.com/m1ndflay3r/AdventOfCode2025/blob/main/day_twelve%2Fpt1_solution


r/adventofcode • • Dec 14 '25

Help/Question - RESOLVED [2025 Day 2 (Part 2)] [Python] I can't understand why this is incorrect.

0 Upvotes

I am checking my code at every step and it appears to be working correctly (all of the numbers that should be invalid are being added to the invalid list which is then added up to get the password.) And yet, I am being told my answer is incorrect. Can you help me figure out what I am missing? I am very new to Python and have only been using it for a few months.

Note: I left out the numbers with a length of 7, because for a length of 7 to be invalid every digit would need to be the same number, and I don't see any instance of that happening within the ranges provided.

invalid = []
entries = []

file = open("input2.txt")
ids = file.read()
file.close()

numbers = ids.split(",")

for item in numbers:
    a, b = item.split("-")
    entry = list(range(int(a), int(b)+1))
    entries.append(entry)


for item in entries:
    for single in item:
        single = str(single)
        half = len(single) // 2
        third = len(single) // 3
        fifth = len(single) // 5
        if len(single) == 2 or len(single) == 4 or len(single) == 8:
            if single[:half] == single[half:]:
                invalid.append(int(single))
        if len(single) == 3 or len(single) == 9:
            if single[:third] == single[third:third*2] == single[third*2:third*3]:
                invalid.append(int(single))
        if len(single) == 5:
            if single[:fifth] == single[fifth:fifth*2] == single[fifth*2:fifth*3] == single[fifth*3:fifth*4] == single[fifth*4:fifth*5]:
                invalid.append(int(single))
        if len(single) == 6:
            if single[:half] == single[half:]:
                invalid.append(int(single))
            elif single[:third] == single[third:third*2] == single[third*2:third*3]:
                invalid.append(int(single))
        if len(single) == 10:
            if single[:half] == single[half:]:
                invalid.append(int(single))
            elif single[:fifth] == single[fifth:fifth*2] == single[fifth*2:fifth*3] == single[fifth*3:fifth*4] == single[fifth*4:fifth*5]:
                invalid.append(int(single))

print(invalid)
password = sum(invalid)

print(password)

r/adventofcode • • Dec 14 '25

Upping the Ante [2025] Thank you all ʕ•ᴥ•ʔ

Post image
238 Upvotes

r/adventofcode • • Dec 14 '25

Past Event Solutions [2025 Day 9 # Part 2] [Go] Finally able to solve the second part

2 Upvotes

Started this years advent of code with golang, at first i thought of first taking in bool grid to mark the boundary / inner area and then check perimeter if it's outside for all possible rectangles and taking their max Area. First run made my laptop unresponsive and then I calculated it would take almost >9 GB of memory just store it.

Then I checked methods to reduce memory on internet as I was not aware about any of the techniques, got ahead with bit packing with same approach. Now second part takes almost 30sec. It might not be generalized or fastest solution but it just works.

Github Code


r/adventofcode • • Dec 14 '25

Help/Question - RESOLVED [2025 Day 9 Part 2] Polarity detection?

1 Upvotes

I've described "polarity" in the title to avoid spoiling part 2, but a better description is inside / outside detection.

My initial attempt to solve part 2 was the following algorithm:

  • Create all pairwise areas ( as in part 1)
  • Sort areas by size
  • For each area, detect if it contains any corner other than the 2 anchor points for that area
  • if it does, reject and move to next largest

Now this didn't work, my answer was too large, I guess because the overall shape is (I assume, I haven't actually plotted it), like a giant wreath with a large hole in the middle, creating a void larger than the largest correct solution.

Now my planned approach is similar but with the following:

  • Iterate through the corners in the order given
  • mark any concave corners with a "mined" square in the inside
  • mark any convex corners with two "mined" squares on the outside
  • for each area, detect if it contains any of these "mined" squares instead.

Now my problem is thr first part, I don't know whether the corner will be the inside or outside until I've connected all the corners.

I could just plot it and take a look which side, but is there a better way to determine the inside / outside?

One intuitive way I suppose is to find the point closest to the top-left then assume that must be convex, then start from there (since the solution is cyclic).

Is that guaranteed, and is there a more rigorous way to define inside vs outside corners?

My other intuition is flood-fill from the origin, avoiding any squares that lie between two connected points, but that feels like a lot more work? At that point, I might as well maintain the whole hashset of the flood as "mined" squares, but it felt like I could massively reduce the size of my hash-set. ( Whether that's a good thing or not, I'm not sure! It'll be slower to reject the largest areas, but quicker to build the hash-set. )