day 13 part 1

This commit is contained in:
Dominic 2023-12-13 18:16:27 +01:00
parent 4e186f6221
commit caced29a1f
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 1353 additions and 27 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
// #![allow(clippy::never_loop)]
#![forbid(elided_lifetimes_in_paths, unsafe_code)]
use aoc23::read;
use chumsky::{prelude::*, text::int};
use rayon::iter::{IntoParallelRefIterator as _, ParallelIterator as _};
use chumsky::prelude::*;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum Cell {
@ -48,35 +48,45 @@ fn main() -> anyhow::Result<()> {
let mut rows = Vec::new();
let mut cols = Vec::new();
for Pattern { grid } in &patterns {
'i: for i in 1 .. grid.len() - 1 {
for (pidx, Pattern { grid }) in patterns.iter().enumerate() {
eprintln!("Pattern {pidx}");
'i: for i in 1 .. grid.len() {
for j in 0 .. i.min(grid.len() - i) {
if grid[i - j - 1] != grid[i + j + 1] {
eprintln!("discarding cut {i} due to rows {}/{}", i - j - 1, i + j);
if grid[i - j - 1] != grid[i + j] {
// eprintln!("discarding cut {i} due to rows {}/{}", i - j - 1, i + j);
continue 'i;
}
}
println!("mirroring at row {i}");
rows.push(i);
}
println!("rows: {rows:?}");
// println!("rows: {rows:?}");
'i: for i in 1 .. grid[0].len() - 1 {
'i: for i in 1 .. grid[0].len() {
for j in 0 .. i.min(grid[0].len() - i) {
for k in 0 .. grid.len() {
if grid[k][i - j - 1] != grid[k][i + j] {
eprintln!("discarding cut {i} due to cols {}/{}", i - j - 1, i + j);
for row in grid {
if row[i - j - 1] != row[i + j] {
// eprintln!(
// "discarding cut {i} due to cols {}/{}",
// i - j - 1,
// i + j
// );
continue 'i;
}
}
}
println!("mirroring at col {i}");
cols.push(i);
}
println!("cols: {cols:?}");
// println!("cols: {cols:?}");
// break;
}
// 20464 is too low
println!(
"{}",
rows.iter().sum::<usize>() + 100 * cols.iter().sum::<usize>()
rows.iter().sum::<usize>() * 100 + cols.iter().sum::<usize>()
);
Ok(())