adventofcode

git clone https://git.ce9e.org/adventofcode.git

commit
2e2d9df44e2585a82e61ef303630537aea40c790
parent
cad83dba4d2f173fc0ec6d9db6a3d16393525a0a
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-12-03 06:36
2026-12-03

Diffstat

A 2026/03/solution.rs 47 +++++++++++++++++++++++++++++++++++++++++++++++
A 2026/03/test.txt 7 +++++++

2 files changed, 54 insertions, 0 deletions


diff --git a/2026/03/solution.rs b/2026/03/solution.rs

@@ -0,0 +1,47 @@
   -1     1 use std::cmp;
   -1     2 
   -1     3 #[path = "../lib.rs"]
   -1     4 mod lib;
   -1     5 
   -1     6 fn main() {
   -1     7     let mut rows: usize = 0;
   -1     8     let mut map = vec![];
   -1     9 
   -1    10     for line in lib::iter_input() {
   -1    11         rows += 1;
   -1    12         for c in line.chars() {
   -1    13             map.push(match c {
   -1    14                 '.' => false,
   -1    15                 '#' => true,
   -1    16                 _ => unreachable!(),
   -1    17             });
   -1    18         }
   -1    19     }
   -1    20 
   -1    21     let cols = map.len() / rows;
   -1    22     let mut count1 = 0;
   -1    23     let mut count2 = 0;
   -1    24 
   -1    25     for y in 0..rows {
   -1    26         for x in 0..cols {
   -1    27             if map[y * cols + x] {
   -1    28                 for d1 in 1..cmp::min(rows - y, cols - x) {
   -1    29                     for d2 in 0..cmp::min(rows - y - d1, x + 1) {
   -1    30                         if map[(y + d2) * cols + (x + d1)]
   -1    31                             && map[(y + d1 + d2) * cols + (x + d1 - d2)]
   -1    32                             && map[(y + d1) * cols + (x - d2)]
   -1    33                         {
   -1    34                             count2 += 1;
   -1    35                             if d2 == 0 {
   -1    36                                 count1 += 1;
   -1    37                             }
   -1    38                         }
   -1    39                     }
   -1    40                 }
   -1    41             }
   -1    42         }
   -1    43     }
   -1    44 
   -1    45     println!("part1: {}", count1);
   -1    46     println!("part2: {}", count2);
   -1    47 }

diff --git a/2026/03/test.txt b/2026/03/test.txt

@@ -0,0 +1,7 @@
   -1     1 #..#..#
   -1     2 .......
   -1     3 .......
   -1     4 #..#..#
   -1     5 .......
   -1     6 .......
   -1     7 #..#..#