From a06ae0bf475fda36bb1cbc5b0b7bbf355c499bed Mon Sep 17 00:00:00 2001 From: Aleksa Vuckovic Date: Fri, 15 Dec 2023 03:57:07 +0100 Subject: day13 & day14pt1 --- src/day13pt1.rs | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/day13pt1.rs (limited to 'src/day13pt1.rs') diff --git a/src/day13pt1.rs b/src/day13pt1.rs new file mode 100644 index 0000000..bc71c44 --- /dev/null +++ b/src/day13pt1.rs @@ -0,0 +1,70 @@ +pub fn f(input: Vec>) -> u64 { + for x in 1..input[0].len() { + let mut ind: bool = true; + + for i in 0..input.len() { + if !ind { + break; + } + + for j in 0..x { + if 2 * x - 1 - j >= input[0].len() { + continue; + } + if input[i][j] != input[i][2 * x - 1 - j] { + ind = false; + break; + } + } + } + + if ind { + return x as u64; + } + } + + for y in 1..input.len() { + let mut ind: bool = true; + + for i in 0..y { + if !ind { + break; + } + + for j in 0..input[i].len() { + if 2 * y - 1 - i >= input.len() { + continue; + } + if input[i][j] != input[2 * y - 1 - i][j] { + ind = false; + break; + } + } + } + + if ind { + return (y * 100) as u64; + } + } + + panic!(); +} + +pub fn main() { + let txt = std::fs::read_to_string("./input/day13.txt").unwrap(); + let input = txt + .split("\n\n") + .map(|s| { + s.lines() + .map(|s| s.chars().collect::>()) + .collect::>() + }) + .collect::>(); + + let mut sum: u64 = 0; + for i in input { + sum += f(i); + } + + println!("{}", sum); +} -- cgit v1.2.3