chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Oct 2022 19:23:08 +0000 (20:23 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Oct 2022 19:23:08 +0000 (20:23 +0100)
src/bin/every-corner.rs
src/lib.rs

index 76fe4b73aff7e6163011fbb209bebfbc489ebf79..bb65f7b85967de7d9a8355fff281d61c83be2de7 100644 (file)
@@ -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)?;
   }
 
index f6b1870d2336ce2d705e088dc14f3acf8a3e622d..940312c54309e04dd35304c9e4afeba6addba468 100644 (file)
@@ -28,6 +28,15 @@ pub fn read_vertices() -> impl Iterator<Item=Shape> {
   })
 }
 
+pub fn shape_edges(shape: &Shape) -> impl Iterator<Item=[Point; 2]> + '_ {
+  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)
+}