From b71d053a3e55f370bea5626b8511b1c5a7cbf0f7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 29 Oct 2022 20:51:09 +0100 Subject: [PATCH] wip settlings --- src/bin/settlings.rs | 34 ++-------------------------------- src/lib.rs | 11 ++++++++--- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/bin/settlings.rs b/src/bin/settlings.rs index 7f9bb74..67ec0d4 100644 --- a/src/bin/settlings.rs +++ b/src/bin/settlings.rs @@ -4,39 +4,9 @@ use z3_treefoil::*; fn main() -> io::Result<()> { for shape in read_vertices() { - - - let has_all_corners = - iter::repeat([0,MAX].into_iter()) - .take(DIM) - .multi_cartesian_product() - .all(|need| shape.iter().any(|got| &got[..]==need)); - - if !has_all_corners { continue } - - if !has_all_corners { continue } - - let middle_vertices = - iter::repeat([1,2].into_iter()) - .take(DIM) - .multi_cartesian_product() - .filter(|need| shape.iter().any(|got| &got[..]==need)) - .count(); - - print!("{} ", middle_vertices); - - let mut edges_middlish = [0; 3]; - - for ab in shape_edges(&shape) { - let middles = ab.iter().filter(|p| point_middle(p)).count(); - edges_middlish[middles] += 1; - } - - for em in &edges_middlish { - print!("{:2} ", em); + for shape2 in shape_all_flippings(&shape) { + print_shape(&shape2)?; } - - print_shape(&shape)?; } Ok(()) diff --git a/src/lib.rs b/src/lib.rs index fe0b2ff..1a29be4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,13 +19,18 @@ pub fn read_vertices() -> impl Iterator { io::stdin().lines().map(|l| { let l = l.unwrap(); let mut current: Point = default(); - l.chars().map(|cx| { + let mut points = l.chars().map(|cx| { let cl = cx.to_ascii_lowercase(); let d = if cx == cl { -1 } else { 1 }; let i = cl as usize - 'x' as usize; current[i] += d; current - }).collect() + }).collect_vec(); + for i in 0..DIM { + let min = points.iter().map(|p| p[i]).min().unwrap(); + for p in &mut points { p[i] -= min; } + } + points }) } @@ -38,7 +43,7 @@ pub fn shape_edges(shape: &Shape) -> impl Iterator + '_ { .map(|(&a,&b)| [a,b]) } -pub fn all_flippings(shape: &Shape) -> impl Iterator + '_ { +pub fn shape_all_flippings(shape: &Shape) -> impl Iterator + '_ { iter::repeat([false,true].into_iter()) .take(DIM) .multi_cartesian_product() -- 2.30.2