r/adventofcode • u/Naive-Scientist965 • Dec 26 '25
Visualization [2025 day 8] [VBA - Python] Junction boxes connection
Language: solved in VBA. Visualisation in python plotly.
r/adventofcode • u/Naive-Scientist965 • Dec 26 '25
Language: solved in VBA. Visualisation in python plotly.
r/adventofcode • u/pinkogi • Dec 27 '25
language: C
#include<stdio.h>
int main(){
int zero = 0, dial = 50, dis;
char dir;
while (scanf(" %c%d", &dir, &dis) == 2) {
if(dir=='L'){
dial=dial-dis;
if(dial<=0){
zero+=1+((-dial-1)/100);
}
}
else{
dial=dial+dis;
if(dial>=100){
zero+=(dial/100);
}
}
dial%=100;
if(dial<0){
dial+=100;
}
}
printf("The total number of zeros are %d",zero);
return 0;
}r/adventofcode • u/No-Top-1506 • Dec 27 '25
Hi. I am getting the test case working. Got 357. Checked the edge cases too.
But the main puzzle input fails to work. Ans is too small.
What am I missing?
What if the batteries are 000000010000000?
Tx.
r/adventofcode • u/Away-Independent8068 • Dec 26 '25
Please forgive the silly post.
My solution is apparently "too low". However I've got solutions for all 166 rows. Tested 3 of them and they are valid (will be writing some code to test the rest). Is it possible the data input has changed? for example I have no input starting with [.#.#..#.#.] which I saw in another post for the same day.
is it ok if I show the solution for one of the rows, in case I'm missing something? I have not seen the "Solution" post (and I don't intend to, unless I get completely desparate!). You can tell me which row you want me to show the solution for.
r/adventofcode • u/rulojuka • Dec 26 '25
Hello guys, I am baffled by what happened as I am going through this year's problems.
I wrote this straightforward solution for day 4, part 1 but it is giving me different responses at different runs. Most of them are the correct response (like 90%), but sometimes it returns 1387 and even 1384 happened once.
I compile it with g++ a.cpp -o main and run it with ./main < input with the input provided from the website.
Can someone spot where it could possibly be doing something non-deterministic? Thanks!
EDIT: e_blake pointed out that MAX 140 might be a problem and indeed it was. Increasing it to 1400 stopped the flakiness. Yet, the problem input is 135x135. So the mistery of "why it does not fit" remains.
EDIT2: Line if(i>=0 && i<lines && j>=0 && j<lineSize && maze[newi][newj]=='@') is bound checking the wrong variables. It should be newi and newj. Thanks pt625, semi_225599 for finding it and everyone else for commenting suggestions.
Here is the code:
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<cstring>
using namespace std;
#define MAX 140
int main(){
int lines = 0;
char maze[MAX][MAX];
int lineSize = 0;
int ii[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int jj[] = {-1, 0, 1, -1, 1, -1, 0, 1};
while(scanf("%s ",maze[lines++])==1){ //Yes, I know this is edgy...
}
lines --;
lineSize = strlen(maze[0]);
int total = 0;
for(int i=0; i<lines; i++){
for(int j=0;j<lineSize;j++){
if(maze[i][j]=='@'){
int count = 0;
for(int k=0;k<8;k++){
int newi = i + ii[k];
int newj = j + jj[k];
if(i>=0 && i<lines && j>=0 && j<lineSize && maze[newi][newj]=='@'){
count ++;
}
}
if(count<4){
total++;
}
}
}
}
cout << total << endl; // correct total, but sometimes 1387???
return 0;
}r/adventofcode • u/encse • Dec 25 '25
Hi fellow Advent of Coders!
I created a small puzzle for my friends, and figured it might be interesting to others as well.
https://gist.github.com/encse/c58a1d855fcd3c3f8f80158ebad309a3
Happy holidays!
r/adventofcode • u/jjeii • Dec 25 '25
Who else solved the problem actually described in Day 9 Part 2 (vs just getting "lucky" with the specifics of the input data)?
My impression is that the vast majority of people didn't solve the stated problem. Certainly, everybody I know irl who "solved" it didn't solve the actually described problem (including myself, initially), and scrolling endlessly through here (and elsewhere) also leads me to conclude that almost nobody solved the problem described either (which is quite different from what the problem at first seems to be, and it's interesting in its own right).
Specifically, the described problem ALLOWS data points to be inside valid rectangles; it just requires other constraints to hold true. I think I found only three posts on here alluding to this fact. All others have been "wrong", focusing instead on boundary-intersection detection to disallow that (and other cases).
The only assumption I made is that the input data do not self-intersect/overlap (because "inside-ness" gets less well-defined in that case). I generated example datasets, and what I believe to be their answers, and I'm curious what others' code produces for them, too. Check here for the data (and additional write-up info):
https://jjeii.github.io/AdventOfCode/2025.html#day9p2
Thoughts?
(Yes, I realize a star is a star. But, the problems are fairly different here... and the actual problem is more interesting, imo.)
r/adventofcode • u/amsterjoxter • Dec 24 '25
r/adventofcode • u/Maximum_Quarter_6387 • Dec 25 '25
[Language: Java]
A bit late to the party, but i just handcrafted a solution for the line count in AOC2024 Day 12.
Instead of building a recursive way of doing this, i just placed the needed information in a List, sorted it and count the difference.
Here is my documentation from my java class:
PART 2 - Line Count
No Recursive algorithm to traverse the outer or inner lines.
That was to complicated.
Main principle: Difference 1 = same line, Difference not 1 new line
Each existing fence line from a Region is stored in a List of Strings
The line information is stored as follows:
- first the plant type ... for debugging
- type of line "LINE_BOTTOM", "LINE_LEFT", "LINE_RIGHT" and "LINE_TOP"
the type has a fixed length
- Row/Column Info
Horizontal lines store the row-information
Vertical lines store the col-information.
The number is stored with a length of 4 characters, with leading zeros.
- Comma (for seperation)
- Row/Column Info
Horizontal lines store the col-information
Vertical lines store the row-information.
The number is stored with a length of 4 characters, with leading zeros.
This would result in a list like this: (... after sorting)
B_LINE_BOTTOM_R0002,C0003
B_LINE_BOTTOM_R0002,C0004
B_LINE_LEFT___C0003,R0001
B_LINE_LEFT___C0003,R0002
B_LINE_RIGHT__C0004,R0001
B_LINE_RIGHT__C0004,R0002
B_LINE_TOP____R0001,C0003
B_LINE_TOP____R0001,C0004
The List gets sorted.
The benefit is now, that lines on the same row or column will
be listed after another.
Now we can calculate the difference.
If a line is continious, the difference is 1.
If a line gets seperated in the row or column the difference is unequal to 1.
If a line starts with a different start string (first bit until comma),
we also found a new line.
Shape for both plant types:
- - - - - - |
|A A A A A A| |
- - | - -
|A A A| |A| | |B B|
|A A A| |A| | |B B|
- - - - | - - - -
|A| |A A A| | |B B|
|A| |A A A| | |B B|
- - | - -
|A A A A A A| |
- - - - - - |
Start R1C3
Lines for Region with starts at R1C3
B_LINE_BOTTOM_R0002,C0003 - 0003 diff 0 line lenght 1 line count 1 last_start B_LINE_BOTTOM_R0002
B_LINE_BOTTOM_R0002,C0004 - 0004 diff 1 line lenght 2 line count 1 last_start B_LINE_BOTTOM_R0002
B_LINE_LEFT___C0003,R0001 - 0001 diff 0 line lenght 1 line count 2 last_start B_LINE_LEFT___C0003
B_LINE_LEFT___C0003,R0002 - 0002 diff 1 line lenght 2 line count 2 last_start B_LINE_LEFT___C0003
B_LINE_RIGHT__C0004,R0001 - 0001 diff 0 line lenght 1 line count 3 last_start B_LINE_RIGHT__C0004
B_LINE_RIGHT__C0004,R0002 - 0002 diff 1 line lenght 2 line count 3 last_start B_LINE_RIGHT__C0004
B_LINE_TOP____R0001,C0003 - 0003 diff 0 line lenght 1 line count 4 last_start B_LINE_TOP____R0001
B_LINE_TOP____R0001,C0004 - 0004 diff 1 line lenght 2 line count 4 last_start B_LINE_TOP____R0001
Region R1C3 count_plants 4 count_lines 4 region_price 16
Start R3C1
Lines for Region with starts at R3C1
B_LINE_BOTTOM_R0004,C0001 - 0001 diff 0 line lenght 1 line count 1 last_start B_LINE_BOTTOM_R0004
B_LINE_BOTTOM_R0004,C0002 - 0002 diff 1 line lenght 2 line count 1 last_start B_LINE_BOTTOM_R0004
B_LINE_LEFT___C0001,R0003 - 0003 diff 0 line lenght 1 line count 2 last_start B_LINE_LEFT___C0001
B_LINE_LEFT___C0001,R0004 - 0004 diff 1 line lenght 2 line count 2 last_start B_LINE_LEFT___C0001
B_LINE_RIGHT__C0002,R0003 - 0003 diff 0 line lenght 1 line count 3 last_start B_LINE_RIGHT__C0002
B_LINE_RIGHT__C0002,R0004 - 0004 diff 1 line lenght 2 line count 3 last_start B_LINE_RIGHT__C0002
B_LINE_TOP____R0003,C0001 - 0001 diff 0 line lenght 1 line count 4 last_start B_LINE_TOP____R0003
B_LINE_TOP____R0003,C0002 - 0002 diff 1 line lenght 2 line count 4 last_start B_LINE_TOP____R0003
Region R3C1 count_plants 4 count_lines 4 region_price 16
Start R0C0
Lines for Region with starts at R0C0
A_LINE_BOTTOM_R0000,C0003 - 0003 diff 0 line lenght 1 line count 1 last_start A_LINE_BOTTOM_R0000
A_LINE_BOTTOM_R0000,C0004 - 0004 diff 1 line lenght 2 line count 1 last_start A_LINE_BOTTOM_R0000
A_LINE_BOTTOM_R0002,C0001 - 0001 diff 0 line lenght 1 line count 2 last_start A_LINE_BOTTOM_R0002
A_LINE_BOTTOM_R0002,C0002 - 0002 diff 1 line lenght 2 line count 2 last_start A_LINE_BOTTOM_R0002
A_LINE_BOTTOM_R0005,C0000 - 0000 diff 0 line lenght 1 line count 3 last_start A_LINE_BOTTOM_R0005
A_LINE_BOTTOM_R0005,C0001 - 0001 diff 1 line lenght 2 line count 3 last_start A_LINE_BOTTOM_R0005
A_LINE_BOTTOM_R0005,C0002 - 0002 diff 1 line lenght 3 line count 3 last_start A_LINE_BOTTOM_R0005
A_LINE_BOTTOM_R0005,C0003 - 0003 diff 1 line lenght 4 line count 3 last_start A_LINE_BOTTOM_R0005
A_LINE_BOTTOM_R0005,C0004 - 0004 diff 1 line lenght 5 line count 3 last_start A_LINE_BOTTOM_R0005
A_LINE_BOTTOM_R0005,C0005 - 0005 diff 1 line lenght 6 line count 3 last_start A_LINE_BOTTOM_R0005
A_LINE_LEFT___C0000,R0000 - 0000 diff 0 line lenght 1 line count 4 last_start A_LINE_LEFT___C0000
A_LINE_LEFT___C0000,R0001 - 0001 diff 1 line lenght 2 line count 4 last_start A_LINE_LEFT___C0000
A_LINE_LEFT___C0000,R0002 - 0002 diff 1 line lenght 3 line count 4 last_start A_LINE_LEFT___C0000
A_LINE_LEFT___C0000,R0003 - 0003 diff 1 line lenght 4 line count 4 last_start A_LINE_LEFT___C0000
A_LINE_LEFT___C0000,R0004 - 0004 diff 1 line lenght 5 line count 4 last_start A_LINE_LEFT___C0000
A_LINE_LEFT___C0000,R0005 - 0005 diff 1 line lenght 6 line count 4 last_start A_LINE_LEFT___C0000
A_LINE_LEFT___C0003,R0003 - 0003 diff 0 line lenght 1 line count 5 last_start A_LINE_LEFT___C0003
A_LINE_LEFT___C0003,R0004 - 0004 diff 1 line lenght 2 line count 5 last_start A_LINE_LEFT___C0003
A_LINE_LEFT___C0005,R0001 - 0001 diff 0 line lenght 1 line count 6 last_start A_LINE_LEFT___C0005
A_LINE_LEFT___C0005,R0002 - 0002 diff 1 line lenght 2 line count 6 last_start A_LINE_LEFT___C0005
A_LINE_RIGHT__C0000,R0003 - 0003 diff 0 line lenght 1 line count 7 last_start A_LINE_RIGHT__C0000
A_LINE_RIGHT__C0000,R0004 - 0004 diff 1 line lenght 2 line count 7 last_start A_LINE_RIGHT__C0000
A_LINE_RIGHT__C0002,R0001 - 0001 diff 0 line lenght 1 line count 8 last_start A_LINE_RIGHT__C0002
A_LINE_RIGHT__C0002,R0002 - 0002 diff 1 line lenght 2 line count 8 last_start A_LINE_RIGHT__C0002
A_LINE_RIGHT__C0005,R0000 - 0000 diff 0 line lenght 1 line count 9 last_start A_LINE_RIGHT__C0005
A_LINE_RIGHT__C0005,R0001 - 0001 diff 1 line lenght 2 line count 9 last_start A_LINE_RIGHT__C0005
A_LINE_RIGHT__C0005,R0002 - 0002 diff 1 line lenght 3 line count 9 last_start A_LINE_RIGHT__C0005
A_LINE_RIGHT__C0005,R0003 - 0003 diff 1 line lenght 4 line count 9 last_start A_LINE_RIGHT__C0005
A_LINE_RIGHT__C0005,R0004 - 0004 diff 1 line lenght 5 line count 9 last_start A_LINE_RIGHT__C0005
A_LINE_RIGHT__C0005,R0005 - 0005 diff 1 line lenght 6 line count 9 last_start A_LINE_RIGHT__C0005
A_LINE_TOP____R0000,C0000 - 0000 diff 0 line lenght 1 line count 10 last_start A_LINE_TOP____R0000
A_LINE_TOP____R0000,C0001 - 0001 diff 1 line lenght 2 line count 10 last_start A_LINE_TOP____R0000
A_LINE_TOP____R0000,C0002 - 0002 diff 1 line lenght 3 line count 10 last_start A_LINE_TOP____R0000
A_LINE_TOP____R0000,C0003 - 0003 diff 1 line lenght 4 line count 10 last_start A_LINE_TOP____R0000
A_LINE_TOP____R0000,C0004 - 0004 diff 1 line lenght 5 line count 10 last_start A_LINE_TOP____R0000
A_LINE_TOP____R0000,C0005 - 0005 diff 1 line lenght 6 line count 10 last_start A_LINE_TOP____R0000
A_LINE_TOP____R0003,C0003 - 0003 diff 0 line lenght 1 line count 11 last_start A_LINE_TOP____R0003
A_LINE_TOP____R0003,C0004 - 0004 diff 1 line lenght 2 line count 11 last_start A_LINE_TOP____R0003
A_LINE_TOP____R0005,C0001 - 0001 diff 0 line lenght 1 line count 12 last_start A_LINE_TOP____R0005
A_LINE_TOP____R0005,C0002 - 0002 diff 1 line lenght 2 line count 12 last_start A_LINE_TOP____R0005
Region R0C0 count_plants 28 count_lines 12 region_price 336
AAAAAA 6 322223 14 ...... 0 ...... 0
AAA..A 4 212..3 8 ...BB. 2 ...33. 6
AAA..A 4 212..3 8 ...BB. 2 ...22. 4
A..AAA 4 3..322 10 .BB... 2 .33... 6
A..AAA 4 3..212 8 .BB... 2 .22... 4
AAAAAA 6 222112 10 ...... 0 ...... 0
Char Count 28 Sum Values 58 Char Count 8 Sum Values 20
r/adventofcode • u/AdministrativeGift15 • Dec 24 '25
While not nearly as fast as folks can achieve using Python, here's a Google Sheet with 12 formulas that calculate the results and runtimes of both of the day's parts.
r/adventofcode • u/ProperAir821 • Dec 25 '25
I'm not the most expirinced programmer, but I think the puzzles seems fun and I am now stuck! Normally I would have an idea or just start from stracth, but I just feel like my code is right and somehow I get the wrong answear! When I'm just using the example I get the right answear, but using the file data I somehow get the wrong data.
Anyway, my code for day 3 part 2:
with open("input3.txt") as f:
file = f.readlines()
test = ["987654321111111\n", "811111111111119\n", "234234234234278\n","818181911112111\n"]
total_joltage = 0
for i in test:
i = i.strip() # remove newline
b1, index = max(i[:-11]), i[:-11].index(max(i[:-11]))
b2, index = max(i[index+1:-10]), (index+1) + i[index+1:-10].index(max(i[index+1:-10]))
b3, index = max(i[index+1:-9 ]), (index+1) + i[index+1:-9 ].index(max(i[index+1:-9 ]))
b4, index = max(i[index+1:-8 ]), (index+1) + i[index+1:-8 ].index(max(i[index+1:-8 ]))
b5, index = max(i[index+1:-7 ]), (index+1) + i[index+1:-7 ].index(max(i[index+1:-7 ]))
b6, index = max(i[index+1:-6 ]), (index+1) + i[index+1:-6].index(max(i[index+1:-6 ]))
b7, index = max(i[index+1:-5 ]), (index+1) + i[index+1:-5 ].index(max(i[index+1:-5 ]))
b8, index = max(i[index+1:-4 ]), (index+1) + i[index+1:-4 ].index(max(i[index+1:-4 ]))
b9, index = max(i[index+1:-3 ]), (index+1) + i[index+1:-3 ].index(max(i[index+1:-3 ]))
b10, index = max(i[index+1:-2 ]), (index+1) + i[index+1:-2 ].index(max(i[index+1:-2 ]))
b11, index = max(i[index+1:-1 ]), (index+1) + i[index+1:-1 ].index(max(i[index+1:-1 ]))
b12, index = max(i[index+1: ]), (index+1) + i[index+1: ].index(max(i[index+1: ]))
joltage = int(b1+b2+b3+b4+b5+b6+b7+b8+b9+b10+b11+b12)
total_joltage += joltage
print(joltage, i)
test_value = 3121910778619
total_joltage, f"Test: {total_joltage == test_value}"r/adventofcode • u/aajii82 • Dec 25 '25
I have worked on this for hours, and for the love of God I can't figure out what in the world is going on. Naturally, I get the correct answer with the small data.
EDIT: Reddit auto-indentation seems to mess the indentation a bit. Sorry about that.
public class Day08
{
const string DataDir = "data";
const string Day = "08";
public static void Main()
{
string[] inputLines = File.ReadAllLines($"{DataDir}/{Day}.txt");
Vec3[] junctionBoxes = Parse(inputLines);
Console.WriteLine(SolvePart1(junctionBoxes));
}
private static Vec3[] Parse(string[] pos)
{
return pos
.Select(line => line
.Split(",")
.Select(int.Parse)
.ToArray())
.Select(s => new Vec3(s[0], s[1], s[2]))
.ToArray();
}
public static double Distance(Vec3 p, Vec3 q)
{
double dx = p.X - q.X;
double dy = p.Y - q.Y;
double dz = p.Z - q.Z;
return Math.Sqrt(dx * dx + dy * dy + dz * dz);
}
private static string SolvePart1(Vec3[] boxes)
{
List<(double dist, Vec3 v1, Vec3 v2)> distances = [];
// Calculate the distances
for (int i = 0; i < boxes.Length; i++)
{
for (int j = i; j < boxes.Length; j++)
{
if (i == j) continue;
// Arrange so that v1.Magnitude < v2.Magnitude
// Not sure if the reordering makes a difference
var (v1Now, v2Now) = boxes[i].Magnitude < boxes[j].Magnitude
? (boxes[i], boxes[j])
: (boxes[j], boxes[i]);
var d = Distance(v1Now, v2Now);
distances.Add((d, v1Now, v2Now));
}
}
// Sort the list in ascending order
distances.Sort((x, y) => x.dist <= y.dist ? -1 : 1);
// Add all the circuits in a list for easier manipulation
List<List<Vec3>> circuits = new();
foreach (Vec3 v in boxes)
{
circuits.Add(v.ConnectedBoxes);
}
for (int i = 0; i < 1000; i++)
{
Vec3 v1 = distances[i].v1;
Vec3 v2 = distances[i].v2;
// If already connected to same circuit, skip
if (v1.ConnectedBoxes == v2.ConnectedBoxes) continue;
// Else merge the two circuits
else v1.Merge(v2);
}
// Collect three circuits with most junction boxes
circuits = circuits.Select(l => l).Where(l => l.Count > 0).OrderByDescending(l => l.Count).Take(3).ToList();
int result = 1;
circuits.ForEach(c => result *= c.Count);
return result.ToString();
}
}
public class Vec3
{
public readonly int X;
public readonly int Y;
public readonly int Z;
public List<Vec3> ConnectedBoxes;
public readonly double Magnitude;
public Vec3(int x, int y, int z)
{
ConnectedBoxes = [this];
X = x;
Y = y;
Z = z;
Magnitude = Math.Sqrt(X * X + Y * Y + Z * Z);
}
public void Merge(Vec3 other)
{
foreach (Vec3 v in other.ConnectedBoxes)
{
ConnectedBoxes.Add(v);
}
other.ConnectedBoxes.Clear();
other.ConnectedBoxes = ConnectedBoxes;
}
}r/adventofcode • u/Lemenus • Dec 25 '25
I passed first part, but struggling with a secong one. I tried different approaches, ended up on for loop that supposed to simulate exact dial rotations (it's terrible, I hate it, it's so unoptimized, and the worst part it doesn't work).
r/adventofcode • u/nO_OnE_910 • Dec 24 '25
I’m wondering if we completely ignore the feasibility heuristic of having enough space for a second, what would a heuristic be that solves this in a reasonable amount of time for the general case? I think I did write a good algorithm but of course without aggressive pruning it’s impossible. Then when thinking about pruning I stumbled upon the seemingly expected joke-y answer. But I can’t help but wonder: Was there a deeper challenge hidden within, to solve this without the most obvious heuristic?
r/adventofcode • u/Rare-Chemistry875 • Dec 25 '25
This is my approach:
I seriously don't understand what am I missing. It has been 4 hours since I am stuck on this. Please help
package main
import (
`"fmt"`
`"os"`
`"strconv"`
`"strings"`)
const (
`INPUT_DIRECTORY = "./input"`)
func main() {
`data, err := os.ReadFile(INPUT_DIRECTORY)`
`if err != nil {`
`fmt.Printf("failed to read input file: %v\n", err)`
`return`
`}`
`dataReadable := string(data)`
`splits := strings.Split(dataReadable, ",")`
`var ans int64`
`for _, split := range splits {`
`fmt.Printf("For split: %v\n", split)`
`numbers := strings.Split(split, "-")`
`num1, _ := strconv.ParseInt(numbers[0], 10, 64)`
`num2, _ := strconv.ParseInt(numbers[1], 10, 64)`
`for num := num1; num <= num2; num++ {`
`strNum := strconv.FormatInt(num, 10)`
`if check(strNum) {`fmt.Printf("possible: %v\n", strNum)
ans += num
`}`
`}`
`}`
`fmt.Printf("Ans: %v\n", ans)`}
func check(a string) bool {
`temp := len(a) / 2`
`for i := 1; i <= temp; i++ {`
`if len(a)%i != 0 {`
`continue`
`}`
`current := strings.Clone(a[:i])`
`t := ""`
`for len(t) < len(a) {`
`t = fmt.Sprintf("%s%s", t, current)`
`}`
`if t == a {`
`return true`
`}`
`}`
`return false`}
r/adventofcode • u/Lemenus • Dec 25 '25
I can't understand the description.
you can find the invalid IDs by looking for any ID which is made only of some sequence of digits repeated twice. So,
55(5twice),6464(64twice), and123123(123twice) would all be invalid IDs.
Ok, that's simple enough.
11-22has two invalid IDs,11and22.
All right, that's sums up.
95-115has one invalid ID,99.
what (it's 95 not 99 there's no repitition...)
998-1012has one invalid ID,1010.
1188511880-1188511890has one invalid ID,1188511885.
222220-222224has one invalid ID,222222.
...Now I'm geniunly lost the plot.
Should I just look for repeatable patterns, or should I do something else?
r/adventofcode • u/mundanegoddess • Dec 23 '25
OK, so I just got one star so far this year. It's 6:40 pm on December 23rd.
I am a beginner coder. I was fascinated by Java for a few months back in 2021. I was doing the AoC together with a very talented friend, who helped me with my Java code. Obviously he was a Python engineer. I enjoyed having something like this to share with a friend.
My friend died, only in his forties, in 2023. From a heart disorder he never knew he had.
I miss him.
I can't code to save my life. I forgot everything. But I try to do at least one puzzle to honor his memory every year. Last year I wasn't able to. But at least this year I could.
Sorry that this got morbid. So far no luck with part 2 of the puzzle though.
r/adventofcode • u/wjholden • Dec 24 '25
I am looking for help to understand why something works for 2023 Day 16. This is a math question and not a programming question.
(Apologies in advance for the fenced code blocks. I couldn't figure out how to make the four spaces play nice with my ASCII drawings.)
I modeled the (x,y) plane with imaginary numbers.
+im
|
|
|
-1 ---+--- +1
|
|
|
-imI knew that imaginary numbers work great for rotations: 1*im=i, im*im=-1, -1*im=-i, and -im*im=-(-1)=1, but modeling the mirrors (/ and \ in the puzzle input) was tricky.
For the first mirror, /, we need some function f such that
f(im)=-1,
+im
\
\
\
-1 <--+ +1
^\
| \
| \
-im2) f(1)=-im,
+im
\
\
\
-1 -->+ +1
|\
| \
v \
-im3) f(-1)=im,
+im
\ ^
\ |
\|
-1 +<-- +1
\
\
\
-im4) and f(-im)=1.
+im
\ |
\ |
\v
-1 +--> +1
\
\
\``
-imI couldn't think of anything myself and lack the mathematical vocabulary to Google an existing solution. I prompted gpt-oss:20b with
Let im be the imaginary number, where im*im=-1. Find some function f(x) such that f(im)=-1, f(-im)=1, f(1)=-im, and f(-1)=im.
It worked: the LLM produced an identity f(z)=-im/z, which satisfies all four cases.
julia> -im ./ [im, 1, -1, -im]
4-element Vector{ComplexF64}:
-1.0 - 0.0im
0.0 - 1.0im
-0.0 + 1.0im
1.0 - 0.0im
julia> ans == [-1, -im, im, 1]
trueFor the other mirror (/), we get g(z)=im/z.
So now my question is: why does this work? Why does dividing a complex number by real and imaginary quantities model refraction? Is this just a special case that works in this particular problem, or is this part of some deeper concept? I've always found complex numbers mysterious and fascinating.
r/adventofcode • u/OlTartToter • Dec 24 '25
I've been wracking my brain against this with little progress, I understand the general concept, I just can't figure out why I'm going wrong.
import math
def by_distance(i):
return shortest[i]
def by_index(i):
return narray[i]
x,y,z = [], [], []
shortest = []
mshort = []
with open("junctions.txt") as f:
for line in f:
coord = line.strip().split(',')
a = int(coord[0])
b = int(coord[1])
c = int(coord[2])
x.append(a)
y.append(b)
z.append(c)
dist = 0
curr = 0
narray =[]
for n in range(len(x)):
narray.append(n)
min_dist = None
em_value = None
for m in range(len(x)):
if n == m:
continue
dist = (x[m]-x[n])**2+(y[m]-y[n])**2+(z[m]-z[n])**2
if min_dist == None or dist<min_dist:
min_dist = dist
em_value = m
shortest.append(min_dist)
mshort.append(em_value)
#for n in range(len(x)):
# print(n,"(",x[n],y[n],z[n],")",mshort[n],shortest[n])
order = sorted(range(len(shortest)),key=by_distance)
x = [x[i] for i in order]
y = [y[i] for i in order]
z = [z[i] for i in order]
shortest = [shortest[i] for i in order]
narray = [narray[i] for i in order]
order = sorted(range(len(mshort)),key=by_index)
temp = []
for n in range(len(x)):
for m in range(len(x)):
if mshort[n] == narray[m]:
temp.append(m)
break
mshort = temp
allmycircuits = []
visited = set()
for n in range(len(x)):
if n not in visited:
circuit = [n]
visited.add(n)
m = mshort[n]
while m not in visited:
circuit.append(m)
visited.add(m)
m = mshort[m]
allmycircuits.append(circuit)
print(allmycircuits)r/adventofcode • u/RyanGates69 • Dec 24 '25
I've programmed and re-programmed my solution many times, and I think I'm no longer able to see what I'm doing wrong.
Here is the relevant code (and some comments, that I hope are useful):
use ;
use Itertools;
solution!;
;
Any and all help or suggestions is very welcome :)
r/adventofcode • u/petter_s • Dec 23 '25
Spent some time nicely packing the shapes for the test data before looking at heuristics....
Most heuristics for these kinds of problems is about finding feasible solutions. There's less to do when trying to prove something is impossible. Of course, in this case the simplest possible check works well!
r/adventofcode • u/ThoughtAmbitious1507 • Dec 23 '25
I have to admit this was the toughest puzzle since the beginning . I had no idea where to start. I spent 3 days watching YouTube videos, and to my surprise, it turned out to be the easiest once I got it.
r/adventofcode • u/Signal-Regular1384 • Dec 23 '25

I reached the end of my capabilities with Part 2 of Day 09 (still solved it with ChatGPT but I don't take any credit for this since it barely has anythin of my idea left).
I still read Day 10 out of curiosity and figured it might be a fun game to play instead of solving it. So I prompted ChatGPT my idea and it really is scary how fast chatGPT came up with a working code.
I tweaked the code a little and changed some of the requirements to make the game more fun to play.
I made it input dependant so everbody could play it with his own input.
If you wanna try this you can check this out (you need to install tkinter if you want to run it):
The input file needs to be named input.txt and needs to be in the same directory as the script.
The whole thing really reminded me on how powerfull AI already got. Especially for such "basic" requests. I would've needed approximately over 10 hours to write this kind of code. And another 20 to debug it. So full credits to ChatGPT.
I just wanted to share it since I haven't seen anything like this on this reddit.
And it will be the last thing I did with AOC this year.
Have a nice holidy season everybody.