23

Day 3: Foggy Forest

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

you are viewing a single comment's thread
view the rest of the comments
[-] mcmodknower@programming.dev 4 points 1 day ago* (last edited 1 day ago)

Rust

Brute force (check for all possible squares if they exist). I could have skipped the inner loop(s) for the delta(s), but forgot about that possibility during coding and it was still fast enough for me.

Solution

use std::fs;

fn main() {
    let contents = fs::read_to_string("../../inputs/2026/3")
	.expect("Could not read input file");
    // let contents = "";
    let size = contents.lines().next().unwrap().len();

    let mut arr = vec![vec![false; size]; size];

    let mut x = 0;
    for line in contents.lines() {
	let mut y = 0;
	for c in line.chars() {
	    if c == '#' {
		arr[x][y] = true;
	    }
	    y+=1;
	}
	x+=1;
    }

    let mut sum = 0;
    for x in 0..size-1 {
	for y in 0..size-1 {
	    for d in 1..(size-x).min(size-y) {
		if arr[x][y] && arr[x][y+d] && arr[x+d][y] && arr[x+d][y+d] {
		    sum += 1;
		}
	    }
	}
    }

    println!("p1: {}", sum);

    let mut sum = 0;
    for x in 0..size-1 {
	for y in 0..size-1 {
	    for dx in 0..(size-x).min(y+1) {
		for dy in 1..(size-x-dx).min(size-y) {
		    if arr[x][y] && arr[x+dx][y+dy] && arr[x+dy][y-dx] && arr[x+dx+dy][y+dy-dx] {
			sum += 1;
		    }
		}
	    }
	}
    }

    println!("p2: {}", sum);
}

this post was submitted on 03 Dec 2026
23 points (100.0% liked)

Advent Of Code

1278 readers
56 users here now

An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Everybody Codes is another collection of programming puzzles with seasonal events.

EC 2025

AoC 2026

Solution Threads

M T W T F S S
1 2 3 4 5 6
7 8 9 10 11 12

Visualisations Megathread

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 3 years ago
MODERATORS