adventofcode

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

commit
22e683203821c42cc9b0ed4646909345dcd378bf
parent
2e2d9df44e2585a82e61ef303630537aea40c790
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-12-04 23:19
2026-12-04

Diffstat

A 2026/04/solution.rs 43 +++++++++++++++++++++++++++++++++++++++++++
A 2026/04/test.txt 6 ++++++
A 2026/04/test2.txt 14 ++++++++++++++

3 files changed, 63 insertions, 0 deletions


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

@@ -0,0 +1,43 @@
   -1     1 #[path = "../lib.rs"]
   -1     2 mod lib;
   -1     3 
   -1     4 fn check_period(chars: &Vec<char>, len: usize) -> bool {
   -1     5     for i in 0..chars.len() {
   -1     6         if chars[i] == '?' {
   -1     7             continue;
   -1     8         }
   -1     9         let mut j = i + len;
   -1    10         while j < chars.len() {
   -1    11             if chars[j] != chars[i] && chars[j] != '?' {
   -1    12                 return false;
   -1    13             }
   -1    14             j += len;
   -1    15         }
   -1    16     }
   -1    17     return true;
   -1    18 }
   -1    19 
   -1    20 fn shortest_period(chars: &Vec<char>) -> usize {
   -1    21     for len in 1..chars.len() {
   -1    22         if check_period(&chars, len) {
   -1    23             return len;
   -1    24         }
   -1    25     }
   -1    26     return chars.len();
   -1    27 }
   -1    28 
   -1    29 fn main() {
   -1    30     let mut count1 = 0;
   -1    31     let mut total_chars = vec![];
   -1    32 
   -1    33     for line in lib::iter_input() {
   -1    34         let mut chars: Vec<char> = line.chars().collect();
   -1    35         count1 += shortest_period(&chars);
   -1    36         total_chars.append(&mut chars);
   -1    37     }
   -1    38 
   -1    39     let count2 = shortest_period(&total_chars);
   -1    40 
   -1    41     println!("part1: {}", count1);
   -1    42     println!("part2: {}", count2);
   -1    43 }

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

@@ -0,0 +1,6 @@
   -1     1 rgbrgbrgbr
   -1     2 ?rv
   -1     3 o??v???y
   -1     4 ??bg?v??
   -1     5 ??b?????
   -1     6 ???

diff --git a/2026/04/test2.txt b/2026/04/test2.txt

@@ -0,0 +1,14 @@
   -1     1 rro??
   -1     2 ?g
   -1     3 ?g???
   -1     4 ??r?????
   -1     5 ??g?
   -1     6 ??
   -1     7 yy?v?o
   -1     8 ???v
   -1     9 b?g??
   -1    10 ?y??v?or
   -1    11 ????r?o
   -1    12 ??
   -1    13 ?????
   -1    14 ?r??v?r