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

index 940312c54309e04dd35304c9e4afeba6addba468..fe0b2ff29717b115159b9670a5f60f708f644c92 100644 (file)
@@ -4,6 +4,7 @@ pub use std::io;
 pub use std::io::Write as _;
 pub use std::iter;
 
+pub use itertools::izip;
 pub use itertools::Itertools as _;
 
 pub fn default<T: Default>() -> T { Default::default() }
@@ -37,6 +38,21 @@ 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> + '_ {
+  iter::repeat([false,true].into_iter())
+    .take(DIM)
+    .multi_cartesian_product()
+    .map(|inv: Vec<bool>| {
+      shape.iter().map(|p| {
+        let mut inv = inv.iter();
+        p.map(|c| {
+          if *inv.next().unwrap() { MAX-c } else { c }
+        })
+      })
+        .collect_vec()
+    })
+}
+
 pub fn print_shape(shape: &Shape) -> io::Result<()> {
   let mut o = io::stdout().lock();
   for vx in shape {