day 13 part 1
This commit is contained in:
parent
4e186f6221
commit
caced29a1f
2 changed files with 1353 additions and 27 deletions
1344
inputs/day13.txt
1344
inputs/day13.txt
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,8 @@
|
||||||
|
// #![allow(clippy::never_loop)]
|
||||||
#![forbid(elided_lifetimes_in_paths, unsafe_code)]
|
#![forbid(elided_lifetimes_in_paths, unsafe_code)]
|
||||||
|
|
||||||
use aoc23::read;
|
use aoc23::read;
|
||||||
use chumsky::{prelude::*, text::int};
|
use chumsky::prelude::*;
|
||||||
use rayon::iter::{IntoParallelRefIterator as _, ParallelIterator as _};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
enum Cell {
|
enum Cell {
|
||||||
|
@ -48,35 +48,45 @@ fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let mut rows = Vec::new();
|
let mut rows = Vec::new();
|
||||||
let mut cols = Vec::new();
|
let mut cols = Vec::new();
|
||||||
for Pattern { grid } in &patterns {
|
for (pidx, Pattern { grid }) in patterns.iter().enumerate() {
|
||||||
'i: for i in 1 .. grid.len() - 1 {
|
eprintln!("Pattern {pidx}");
|
||||||
|
'i: for i in 1 .. grid.len() {
|
||||||
for j in 0 .. i.min(grid.len() - i) {
|
for j in 0 .. i.min(grid.len() - i) {
|
||||||
if grid[i - j - 1] != grid[i + j + 1] {
|
if grid[i - j - 1] != grid[i + j] {
|
||||||
eprintln!("discarding cut {i} due to rows {}/{}", i - j - 1, i + j);
|
// eprintln!("discarding cut {i} due to rows {}/{}", i - j - 1, i + j);
|
||||||
continue 'i;
|
continue 'i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println!("mirroring at row {i}");
|
||||||
rows.push(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 j in 0 .. i.min(grid[0].len() - i) {
|
||||||
for k in 0 .. grid.len() {
|
for row in grid {
|
||||||
if grid[k][i - j - 1] != grid[k][i + j] {
|
if row[i - j - 1] != row[i + j] {
|
||||||
eprintln!("discarding cut {i} due to cols {}/{}", i - j - 1, i + j);
|
// eprintln!(
|
||||||
|
// "discarding cut {i} due to cols {}/{}",
|
||||||
|
// i - j - 1,
|
||||||
|
// i + j
|
||||||
|
// );
|
||||||
continue 'i;
|
continue 'i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println!("mirroring at col {i}");
|
||||||
cols.push(i);
|
cols.push(i);
|
||||||
}
|
}
|
||||||
println!("cols: {cols:?}");
|
// println!("cols: {cols:?}");
|
||||||
|
|
||||||
|
// break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 20464 is too low
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
rows.iter().sum::<usize>() + 100 * cols.iter().sum::<usize>()
|
rows.iter().sum::<usize>() * 100 + cols.iter().sum::<usize>()
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue