summaryrefslogtreecommitdiff
path: root/2023
diff options
context:
space:
mode:
authornekineki <nekineki@nekineki.net>2023-12-13 11:11:45 +0100
committernekineki <nekineki@nekineki.net>2023-12-13 11:11:45 +0100
commit7ca63f60e8f7658345361839f02552760cbc81bb (patch)
treeec7c46a9af342f687be67da52fcab6e3a867a590 /2023
parent8eb7e8495cb3df4ccae5f162c1dfbd66229fdfe4 (diff)
day13 part2
Diffstat (limited to '2023')
-rw-r--r--2023/day13.rs61
1 files changed, 34 insertions, 27 deletions
diff --git a/2023/day13.rs b/2023/day13.rs
index b2f2b05..de11ded 100644
--- a/2023/day13.rs
+++ b/2023/day13.rs
@@ -1,6 +1,4 @@
#![allow(dead_code)]
-#![allow(unused_variables)]
-#![allow(unused_mut)]
use std::fs::File;
use std::io::Read;
@@ -25,13 +23,17 @@ fn lines_mirrored(arr: &Vec<Vec<bool>>, start: usize) -> bool {
return true;
}
-fn mirror_horizontal_line(arr: &Vec<Vec<bool>>) -> usize {
+fn mirror_horizontal_line(arr: &Vec<Vec<bool>>) -> Vec<usize> {
+ let mut out = Vec::new();
for i in 0..arr.len() - 1 {
if lines_mirrored(arr, i) {
- return i + 1;
+ out.push(i + 1);
}
}
- return 0;
+ if out.len() == 0 {
+ out.push(0);
+ }
+ out
}
fn print_arr(arr: &Vec<Vec<bool>>) {
@@ -70,49 +72,52 @@ fn main() {
arr.push(l);
}
- let (x, y) = (
- mirror_horizontal_line(&transpose(arr.clone())),
- mirror_horizontal_line(&arr),
+ let (x1, y1) = (
+ mirror_horizontal_line(&transpose(arr.clone()))[0],
+ mirror_horizontal_line(&arr)[0],
);
- res1 += x + 100 * y;
- println!("aaa {x} {y}");
+ res1 += x1 + 100 * y1;
+
+ if x1 != 0 && y1 != 0 {
+ panic!("asdf");
+ }
- if x != 0 && y != 0 {
+ if x1 == 0 && y1 == 0 {
panic!("asdf");
}
+ // print_arr(&arr);
+
'outer: for i in 0..arr.len() {
for j in 0..arr[0].len() {
let mut a = arr.clone();
a[i][j] ^= true;
let (x2, y2) = (
- mirror_horizontal_line(&transpose(a.clone())),
- mirror_horizontal_line(&a),
+ mirror_horizontal_line(&transpose(a.clone()))
+ .into_iter()
+ .filter(|x| *x != x1)
+ .next()
+ .unwrap_or(0),
+ mirror_horizontal_line(&a)
+ .into_iter()
+ .filter(|y| *y != y1)
+ .next()
+ .unwrap_or(0),
);
- if x == 0 {
- if (y != y2) && (y2 != 0) {
- println!("a {x} {y}, {x2} {y2}");
- print_arr(&a);
+ if x1 == 0 {
+ if (y1 != y2) && (y2 != 0) {
res2 += 100 * y2;
break 'outer;
} else if x2 != 0 {
- println!("b {x} {y}, {x2} {y2}");
- print_arr(&a);
res2 += x2;
break 'outer;
}
- }
-
- if y == 0 {
+ } else if y1 == 0 {
if y2 != 0 {
- println!("c {x} {y}, {x2} {y2}");
- print_arr(&a);
res2 += 100 * y2;
break 'outer;
- } else if (x != x2) && (x2 != 0) {
- println!("d {x} {y}, {x2} {y2}");
- print_arr(&a);
+ } else if (x1 != x2) && (x2 != 0) {
res2 += x2;
break 'outer;
}
@@ -123,4 +128,6 @@ fn main() {
println!("res1: {}", res1);
println!("res2: {}", res2);
+ assert_eq!(res1, 37975);
+ assert_eq!(res2, 32497);
}