From a37a51231ea44e17695bc2b27bb4d6be3368c18a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 29 Oct 2022 20:23:08 +0100 Subject: [PATCH] wip --- src/bin/every-corner.rs | 13 ++++++++++++- src/lib.rs | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/bin/every-corner.rs b/src/bin/every-corner.rs index 76fe4b7..bb65f7b 100644 --- a/src/bin/every-corner.rs +++ b/src/bin/every-corner.rs @@ -22,7 +22,18 @@ fn main() -> io::Result<()> { .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); + } + print_shape(&shape)?; } diff --git a/src/lib.rs b/src/lib.rs index f6b1870..940312c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,15 @@ pub fn read_vertices() -> impl Iterator { }) } +pub fn shape_edges(shape: &Shape) -> impl Iterator + '_ { + shape + .iter() + .cycle() + .take(shape.len() + 1) + .tuple_windows() + .map(|(&a,&b)| [a,b]) +} + pub fn print_shape(shape: &Shape) -> io::Result<()> { let mut o = io::stdout().lock(); for vx in shape { @@ -39,3 +48,7 @@ pub fn print_shape(shape: &Shape) -> io::Result<()> { write!(o, "\n")?; Ok(()) } + +pub fn point_middle(point: &Point) -> bool { + point.iter().all(|&c| c == 1 || c == 2) +} -- 2.30.2