diff --git a/data/examples/13.txt b/data/examples/13.txt new file mode 100644 index 000000000..3b6b5cc --- /dev/null +++ b/data/examples/13.txt @@ -0,0 +1,15 @@ +#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..# diff --git a/src/bin/13.rs b/src/bin/13.rs new file mode 100644 index 000000000..658956c --- /dev/null +++ b/src/bin/13.rs @@ -0,0 +1,51 @@ +fn mirror_h(shape: &Vec>) -> Option { + (1..(shape.len() - 1)) + .filter(|&i| { + shape + .iter() + .skip(i) + .zip(shape.iter().take(i).rev()) + .all(|(x, y)| x.iter().zip(y.iter()).all(|(xx, yy)| xx == yy)) + }) + .max() +} +fn mirror_v(shape: &Vec>) -> Option { + let shape = (0..shape[0].len()) + .map(|col| (0..shape.len()).map(|row| shape[row][col]).collect()) + .collect(); + + mirror_h(&shape) +} + +pub fn part_one(input: &str) -> Option { + Some( + input + .split("\n\n") + .map(|x| x.lines().map(|line| line.chars().collect()).collect()) + .map(|shape| { + let v = mirror_v(&shape).unwrap_or(0); + let h = mirror_h(&shape).unwrap_or(0) * 100; + v + h + }) + .sum(), + ) +} + +pub fn part_two(_input: &str) -> Option { + None +} + +aoc::solution!(13); + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn test_part_one() { + assert_eq!(part_one(&aoc::template::read_file("examples", 13)), None); + } + #[test] + fn test_part_two() { + assert_eq!(part_two(&aoc::template::read_file("examples", 13)), None); + } +}