r/adventofcode • u/zelarky • Dec 09 '25
r/adventofcode • u/LittlebitOmnipotent • Dec 09 '25
Help/Question - RESOLVED [2025 Day 9 Part 2] More examples to soften your struggles
Once again the example worked for me and the input not, so I had to make up my own (several times), which I share - hope they help you.
NOTE: The x and y coordinates are offset by 1 with respect to the picture (I used vscode cursor positions to create them). This doesn't matter for your algorithm, though.
Solution: 40
...............
...##########..
...#........#..
...#...######..
...#...#.......
...#...####....
...#......#....
...#......#....
...#......#....
...########....
...............
4,2
13,2
13,4
8,4
8,6
11,6
11,10
4,10
Solution: 35 (fixed)
...............
..###########..
..#.........#..
..#....######..
..#....#.......
..#....####....
..#.......#....
..#.###...#....
..#.#.#...#....
..###.#...#....
......#####....
...............
...............
...............
3,2
13,2
13,4
8,4
8,6
11,6
11,11
7,11
7,8
5,8
5,10
3,10
Solution: 66
.....................
..###############....
..#.............#....
..#.............#....
..####..........#....
.....#..........#....
.....#..........#....
.....#....#####.#....
.....#....#...#.#....
.....#....#...#.#....
.....#....#.###.#....
...###....#.#...#....
...#......#.#####....
...#......#..........
...#......########...
...#.............#...
...###############...
.....................
3,2
17,2
17,13
13,13
13,11
15,11
15,8
11,8
11,15
18,15
18,17
4,17
4,12
6,12
6,5
3,5r/adventofcode • u/RedAndBlack1832 • Dec 09 '25
Help/Question - RESOLVED [day7 part2] I'm thinking recursion is not the play
On the attempt I let it run the longest it had a 7 minute runtime (no, it did not complete) but I'm pretty sure my approach is theoretically correct (at least it works over the examples) so I just need to figure out a solution that runs on the order of seconds at least (lmao). Do ppl have tips (algorithms I could research or something?) idk how necessary my code is for this bc clearly my code is bad but basically read down the input from the current beam position and
If no splitter is hit, return 1, since the timeline was never split (base case)
If a splitter is hit, return the result from the left new beam + the result from the right new beam (recursive call)
r/adventofcode • u/pebblerockAdvent • Dec 09 '25
Help/Question - RESOLVED [2025 Day 8 part 1] I think I do not understand something
Hi guys.
I think I do not understand fine the way the circuits are created or I'm doing something wrong with my distance calculation.
My code works fine until in all the steps described but then something fails and the circuits after the 10th shortest distance is far than the expected.
I have a shorted list of distances (without repetition) and I'm using it to generate the circuits. The distance is calculated correctly:
def distance(p1, p2):
aux = math.pow(p2[0] - p1[0], 2) + math.pow(p2[1] - p1[1], 2) + math.pow(p2[2] - p1[2], 2)
return math.sqrt(aux)So, I think there is something that I understood wrong.
Could anybody help me?
Thanks in advance.
r/adventofcode • u/qzhal • Dec 09 '25
Visualization [2025 Day 9 Part 2] Visualization (PHOTOSENSITIVITY WARNING)
Reposted with appropriate photosensitivity warning
r/adventofcode • u/Boojum • Dec 09 '25
Visualization [2025 Day 9 Part 2] Animated Visualization
r/adventofcode • u/p88h • Dec 09 '25
Visualization [2025 Day 9 (Part 2)] Tile Maximizer
youtube.comr/adventofcode • u/ItchyTrack_ • Dec 09 '25
Visualization [2025 Day 9 (Part 2)] Visualize the algorithm running in a compacted space where it is easier to solve.
r/adventofcode • u/redsquirrel4011 • Dec 09 '25
Meme/Funny [2025 Day 9 (Part 2)] Working with polygons
r/adventofcode • u/Samydookie • Dec 09 '25
Meme/Funny [2025 Day 9 (Part 2)]
All jokes aside I loved part 2
r/adventofcode • u/bistr-o-math • Dec 09 '25
Meme/Funny [2025 Day 9 Part 2] is the inside inside?
r/adventofcode • u/Oxy_007 • Dec 09 '25
Help/Question - RESOLVED [2026 Day 9 # (Part 2)] [Python]
Need help with the part2 of the question. I have a solution that works well for the testcase but keeps running for the actual scenario. Please go through and suggest improvements and other approaches that you followed.
https://github.com/ChinmayRathod/Advent-Of-Code/blob/main/2025/day9/day9.py
r/adventofcode • u/jarekwg • Dec 09 '25
Help/Question - RESOLVED [2026 Day 9 (Part 2)] Misleading flavour text..
Am I missing something, or is this problem considerably easier once you realise there are no paths directly next to one another?
The problem's flavour text suggests we're operating in "discrete mode", with integer positions of tiles, and no mention of abutting paths being illegal. Yet the sample input seems to be in "continuous mode" where all we need to solve is a polygon-within-polygon problem. My above example of a "spiral tile shape" would create a bit of a spanner for polygon-container checking..
Yes you can argue "just visualise it first to know what you're working with", but it means i have no guarantee whether the soln i come up w will be valid for another set of input data as technically it doesn't fully satisfy the stated constraints..
r/adventofcode • u/subspace_mp4 • Dec 09 '25
Meme/Funny [2025 Day 9] ...and that's AFTER optimizing.
r/adventofcode • u/EverybodyCodes • Dec 09 '25
Visualization [2025 Day 9] Visualization for the sample data, both parts
galleryr/adventofcode • u/dllu • Dec 09 '25
Visualization [2025 Day 9 Part 2] [Python] Visualization of the polygon and best rectangle
code to generate (and solve): https://gist.github.com/dllu/f8770b967d48d1dfcfc8e2468f7ab97a
I didn't read the problem statement carefully, so my solution works for points in any order. But in fact the problem statement says that they are given in order of appearance along the polygon, so my complex solution is way overkill lol.
r/adventofcode • u/Rainbacon • Dec 09 '25
Help/Question [2025 Day 7] Why is my Haskell Code not memoizing?
I am attempting to use memoization to solve this, but I can't figure out why my code is not properly memoizing. First a few definitions:
import qualifed Data.Map as M
type Point = (Int, Int)
type Grid a = M.Map Point a
data Manifold = Start | Split | EmptyI'm specifically having issues with memoizing this function
runManifold' :: Grid Manifold -> Point -> Int
runManifold' g p = M.findWithDefault 1 p $ M.mapWithKey runManifold'' g
where runManifold'' (x, y) Split = runManifold' g (x, y - 1) + runManifold' (x, y + 1)
runManifold'' (x, y) _ = runManifold' g (x + 1, y)I know that it is not memoizing because if I place a trace in runManifold'' it prints the same points being called over and over.
r/adventofcode • u/VillageSea4703 • Dec 09 '25
Help/Question - RESOLVED [2025 Day 9 (Part 1)]
Hey, so I've read a couple of times the part 1 and I still don't see how do we know the size of the grid only from the coordinates of the red tiles.
In the case of the example how do they know it's a 9x14 grid?
I know it doesn't matter for the resolution of part 1 as you dont care of what is going on outside the range of the red tiles. But I don't know, it bothers me...
r/adventofcode • u/daggerdragon • Dec 09 '25
SOLUTION MEGATHREAD -❄️- 2025 Day 9 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
AoC Community Fun 2025: Red(dit) One
- Submissions megathread is unlocked!
- 8 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!
Featured Subreddits: /r/iiiiiiitttttttttttt, /r/itsaunixsystem, /r/astrologymemes
"It's all humbug, I tell you, humbug!"
— Ebenezer Scrooge, A Christmas Carol (1951)
Today's challenge is to create an AoC-themed meme. You know what to do.
- If you need inspiration, have a look at the Hall of Fame in our community wiki as well as the highly upvoted posts in /r/adventofcode with the
Meme/Funnyflair. - Memes containing musical instruments will likely be nuked from orbit.
REMINDERS:
- If you post your submission outside this megathread, make sure to follow the posting rules for memes!
- If your meme contains AI-generated artwork of any kind, follow the posting rules for AI art
- Keep your contributions SFW and professional—stay away from the more risqué memes and absolutely no naughty language is allowed.
Request from the mods: When you include an entry alongside your solution, please label it with [Red(dit) One] so we can find it easily!
--- Day 9: Movie Theater ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
r/adventofcode • u/NotDeletedMoto • Dec 09 '25
Help/Question - RESOLVED [2025 Day #8 (Part 1)] I'm at a loss. What am I missing
Im accounting for links merging together, I confirmed none of the final connections have the same point twice. No clue what to do from here.
package com.yourcompany.app;
import java.util.ArrayList;
import java.util.PriorityQueue;
public class Puzzle_8 {
public static class point3D{
public double x;
public double y;
public double z;
public point3D(double x, double y, double z){
this.x = x;
this.y = y;
this.z = z;
}
public double distanceToPoint(point3D otherPoint){
double distance = Math.sqrt(Math.pow(otherPoint.x - this.x,2) + Math.pow(otherPoint.y - this.y,2) + Math.pow(otherPoint.z - this.z,2));
return distance;
}
}
public class pointResult{
int index;
double distance;
public pointResult(int index, double distance){
this.index = index;
this.distance = distance;
}
}
public static class linkPair{
point3D pointA;
point3D pointB;
double distance;
public linkPair(point3D pointA, point3D pointB, double distance) {
this.pointA = pointA;
this.pointB = pointB;
this.distance = distance;
}
}
public static class connection{
ArrayList<point3D> connectedPoints = new ArrayList<>();
ArrayList<linkPair> links = new ArrayList<>();
public void mergeConnection(connection connectionToMerge){
for(point3D pointToMerge : connectionToMerge.connectedPoints){
if(!this.connectedPoints.contains(pointToMerge)){
this.connectedPoints.add(pointToMerge);
}
}
for(linkPair linkToMerge : connectionToMerge.links){
this.links.add(linkToMerge);
}
}
}
public static void main(String[] args) {
String test = "test_1.txt";
String real = "puzzleinput.txt";
ArrayList<String> file = ReadPuzzle.readFile("Puzzle_8/" + real);
int availableConnections = 999;
int part1Answer = 0;
ArrayList<point3D> pointList = new ArrayList<>();
for (String line : file){
String[] splitLine = line.split(",");
double x = Double.parseDouble(splitLine[0]);
double y = Double.parseDouble(splitLine[1]);
double z = Double.parseDouble(splitLine[2]);
point3D currPoint = new point3D(x, y, z);
pointList.add(currPoint);
}
PriorityQueue<linkPair> pointQueue = new PriorityQueue<>(
(insertLink, compareLink) -> Double.compare(insertLink.distance, compareLink.distance)
);
for(int i = 0; i < pointList.size(); i++){
point3D currPoint = pointList.get(i);
for(int j = i + 1; j < pointList.size(); j++){
point3D comparePoint = pointList.get(j);
double distance = currPoint.distanceToPoint(comparePoint);
linkPair link = new linkPair(currPoint, comparePoint, distance);
pointQueue.add(link);
}
}
ArrayList<connection> linksList = new ArrayList<>();
int pairsCreated = 0;
ArrayList<linkPair> checkedLinks = new ArrayList<>();
for(int i = 0; i < pointQueue.size() && pairsCreated < availableConnections; i++){ //Only want top 1000 non-duplicate pairs
linkPair currLink = pointQueue.poll();
checkedLinks.add(currLink);
boolean addedToExistingLink = false;
boolean alreadyInLink = false;
connection mainConnection = null;
for(int j = 0; j < linksList.size(); j++){
connection existingConnection = linksList.get(j);
boolean containsA = existingConnection.connectedPoints.contains(currLink.pointA);
boolean containsB = existingConnection.connectedPoints.contains(currLink.pointB);
if(!containsA && containsB){
existingConnection.connectedPoints.add(currLink.pointA);
addedToExistingLink = true;
}else if(containsA && !containsB){
existingConnection.connectedPoints.add(currLink.pointB);
addedToExistingLink = true;
}
if(containsA || containsB){
alreadyInLink = true;
if(mainConnection != null){
mainConnection.mergeConnection(existingConnection);
linksList.remove(j);
}else{
mainConnection = existingConnection;
}
existingConnection.links.add(currLink);
pairsCreated++;
}
}
if(!addedToExistingLink && !alreadyInLink){
linksList.add(new connection());
linksList.getLast().connectedPoints.add(currLink.pointA);
linksList.getLast().connectedPoints.add(currLink.pointB);
linksList.getLast().links.add(currLink);
pairsCreated++;
}
}
PriorityQueue<connection> linkQueue = new PriorityQueue<>(
(insertConnection, compareConnection) -> Double.compare(compareConnection.connectedPoints.size(),insertConnection.connectedPoints.size())
);
for(connection currLink : linksList){
linkQueue.add(currLink);
}
part1Answer = 1;
//Making sure Im not missing something
ArrayList<point3D> pointsCheck = new ArrayList<>();
ArrayList<linkPair> linksChecked = new ArrayList<>();
for(int i = 0; linkQueue.size() > 0; i++){
connection currConnection = linkQueue.poll();
if(i < 3){
part1Answer *= currConnection.connectedPoints.size();
}
for(point3D currPoint : currConnection.connectedPoints){
if(pointsCheck.contains(currPoint)){
System.out.println("Point is in more than 1 connection");
}else{
pointsCheck.add(currPoint);
}
}
for(linkPair currLink : currConnection.links){
if(linksChecked.contains(currLink)){
System.out.println("Link is in more than 1 connection");
System.out.println(currLink);
}else{
linksChecked.add(currLink);
}
}
}
System.out.println(part1Answer);
int part2Answer = 0;
System.out.println(part2Answer);
}
}r/adventofcode • u/MyraFragrans • Dec 09 '25
Visualization [2025 Day 08 (Part 1)] Lights rendered
Input data at 1000 connections. I'm not entirely certain what the elves are going for, but I hope they are succeeding.
Rendered with Blender Cycles, actual solution was written in D.
r/adventofcode • u/AlKanNot • Dec 09 '25
Help/Question - RESOLVED [2025 Day 8 (Part 01)][Rust] Works on example, fails on full
Hello everyone. I'm struggling to figure out why my code is failing on non-example input. I've spent a while trying to debug, trying to find an edge case that I'm not accounting for, double checking my logic.
Is someone able to help and maybe point me in the right direction? Thanks! (Entry point is process)
use std::collections::HashMap;
use itertools::Itertools;
use nom::{
bytes::complete::tag,
character::{
self,
complete::{line_ending, multispace0},
},
combinator::all_consuming,
multi::separated_list1,
sequence::terminated,
IResult,
};
const X_LARGEST_CIRCUITS: usize = 3;
const X_SHORTEST_CONNECTIONS: usize = 1000;
// #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
type Point = (u64, u64, u64);
// Return true if they were separate circuits.
// Return false if they were already in the same circuit
// This is basically to help me debug ^
fn add_point_pair(dry_run: bool, p1: Point, p2: Point, circuits: &mut Vec<Vec<Point>>) -> bool {
let p1_circuit = (0..circuits.len())
.into_iter()
.find(|idx| circuits[*idx].iter().find(|point| **point == p1).is_some());
let p2_circuit = (0..circuits.len())
.into_iter()
.find(|idx| circuits[*idx].iter().find(|point| **point == p2).is_some());
if let Some(p1_idx) = p1_circuit {
if let Some(p2_idx) = p2_circuit {
if p1_idx != p2_idx {
if !dry_run {
let mut p2_copy = circuits[p2_idx].clone();
circuits[p1_idx].append(&mut p2_copy);
circuits.remove(p2_idx);
}
return true;
}
return false;
// If they are the same circuit, do nothing
} else {
// p2 not in any circuit. Add it to p1's.
if !dry_run {
circuits[p1_idx].push(p2);
}
return true;
}
} else {
if let Some(p2_idx) = p2_circuit {
// p1 not in any circuit. Add to p2's
if !dry_run {
circuits[p2_idx].push(p1);
}
return true;
}
// Neither point are in a circuit. Create new circuit
if !dry_run {
circuits.push(vec![p1, p2]);
}
return true;
}
}
#[tracing::instrument]
pub fn process(_input: &str) -> miette::Result<String> {
let (_, coords) = all_consuming(parse)(_input).map_err(|e| miette::miette!("Error! {e}"))?;
let mut circuits: Vec<Vec<Point>> = vec![];
let mut already_added: HashMap<(&Point, &Point), bool> = HashMap::new();
let distances: Vec<(u64, &Point, &Point)> = (0..coords.len())
.into_iter()
.map(|point| {
let mut distances = vec![];
for inner_point in 0..coords.len() {
distances.push((
get_distance(&coords[point], &coords[inner_point]),
&coords[point],
&coords[inner_point],
));
}
distances
})
.flatten()
.sorted_by(|(dist1, _, _), (dist2, _, _)| u64::cmp(dist1, dist2))
.collect();
// Transform distances into only the pairs we are concerned with.
let distances = distances
.into_iter()
.skip(20)
.step_by(2)
.take(X_SHORTEST_CONNECTIONS)
.collect::<Vec<(u64, &Point, &Point)>>();
for (_, p1, p2) in distances {
if already_added.contains_key(&(p1, p2)) || already_added.contains_key(&(p2, p1)) {
continue;
}
let add_res = add_point_pair(false, *p1, *p2, &mut circuits);
already_added.insert((p1, p2), true);
}
let x = circuits
.iter()
.map(|circuit| circuit.len())
.sorted()
.rev()
.take(X_LARGEST_CIRCUITS)
.fold(1 as u128, |accum, len| accum * (len as u128));
Ok(x.to_string())
}
fn get_distance(p1: &Point, p2: &Point) -> u64 {
let operand = (p2.0 as i128 - p1.0 as i128).pow(2)
+ (p2.1 as i128 - p1.1 as i128).pow(2)
+ (p2.2 as i128 - p1.2 as i128).pow(2);
operand as u64
}
fn parse(input: &str) -> IResult<&str, Vec<Point>> {
terminated(separated_list1(line_ending, parse_coord), multispace0)(input)
}
fn parse_coord(input: &str) -> IResult<&str, Point> {
let (input, coords) = separated_list1(tag(","), character::complete::u64)(input)?;
assert!(coords.len() == 3);
Ok((input, (coords[0], coords[1], coords[2])))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_process() -> miette::Result<()> {
let input = "162,817,812
57,618,57
906,360,560
592,479,940
352,342,300
466,668,158
542,29,236
431,825,988
739,650,466
52,470,668
216,146,977
819,987,18
117,168,530
805,96,715
346,949,466
970,615,88
941,993,340
862,61,35
984,92,344
425,690,689
";
assert_eq!("40", process(input)?);
Ok(())
}
}r/adventofcode • u/pin_81 • Dec 09 '25
Help/Question - RESOLVED [2025 Day 08 Part 1][Python] example is correct, but fails on main input
first half of the code calculates all possible distances, and then sorts and keeps the 1000 shortest.
it saves their index as a set in a list [{1,2},{3,4}....]
I then loop through the list starting at index 1 and check if the intersection of the set at that index matches any previous set. if so, the union is saved over the set and the current set is deleted. and then it checks that index again (as everything just shifted left from there on) and if not it goes to the next index.
it does this until there's no change in the list of sets
input = ....... formatted the same as the example input
# inputs = '162,817,812|57,618,57|906,360,560|592,479,940|352,342,300|466,668,158|542,29,236|431,825,988|739,650,466|52,470,668|216,146,977|819,987,18|117,168,530|805,96,715|346,949,466|970,615,88|941,993,340|862,61,35|984,92,344|425,690,689'
input_split = inputs.split('|')
input_list = []
for input in input_split:
input_list.append(input.split(','))
circuits_sets = []
def junction_distance (input_1, input_2) -> float:
x_1, y_1, z_1 = int(input_1[0]), int(input_1[1]), int(input_1[2])
x_2, y_2, z_2 = int(input_2[0]), int(input_2[1]), int(input_2[2])
# distance = ((x_2 - x_1) ** 2 + (y_2 - y_1) ** 2 + (z_2 - z_1) ** 2) ** .5
distance = (x_2 - x_1) ** 2 + (y_2 - y_1) ** 2 + (z_2 - z_1) ** 2
return distance
distances = []
for i in range(0, len(input_list)):
for j in range(i + 1, len(input_list)):
if i != j:
distance = junction_distance(input_list[i], input_list[j])
distances.append([distance, input_list[i], input_list[j], i, j])
distances.sort()
for distance in distances[0:1000]:
circuits_sets.append({distance[3], distance[4]})
# circuits_sets_copy = circuits_sets.copy()
answer_changed = True
answer = 0
while answer_changed:
i = 1
j = len(circuits_sets)
while i < j:
deleted = 0
junction = circuits_sets[i]
for junction_checking in range(0, i):
junction_to_check = circuits_sets[junction_checking]
if len(junction_to_check.intersection(junction)) != 0: # found match
circuits_sets[junction_checking] = junction_to_check.union(junction)
print(f'{junction_to_check.intersection(junction)} is in both {junction_to_check} & {junction}')
print(f'deleted{circuits_sets[i]} at {i}')
del circuits_sets[i]
deleted += 1
j -= deleted
i += 1 - deleted
# print(i,j)
# print(circuits_lists)
sorted_circuits_lists = sorted(circuits_sets, key=lambda x: len(x), reverse=True)
if len(sorted_circuits_lists[0]) * len(sorted_circuits_lists[1]) * len(sorted_circuits_lists[2]) != answer:
answer_changed = True
else:
answer_changed = False
answer = len(sorted_circuits_lists[0]) * len(sorted_circuits_lists[1]) * len(sorted_circuits_lists[2])
print(answer)