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

index 7f9bb74a0b844b8493e251c4edbfa42626d84fd6..67ec0d4a2def50c7d9f6725b45324e8ee1c3149b 100644 (file)
@@ -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(())
index fe0b2ff29717b115159b9670a5f60f708f644c92..1a29be461241beac5304f161a03c1dc617ba3162 100644 (file)
@@ -19,13 +19,18 @@ pub fn read_vertices() -> impl Iterator<Item=Shape> {
   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<Item=[Point; 2]> + '_ {
     .map(|(&a,&b)| [a,b])
 }
 
-pub fn all_flippings(shape: &Shape) -> impl Iterator<Item=Shape> + '_ {
+pub fn shape_all_flippings(shape: &Shape) -> impl Iterator<Item=Shape> + '_ {
   iter::repeat([false,true].into_iter())
     .take(DIM)
     .multi_cartesian_product()