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

index b814033518f402c47ce1149ca0d370485d2dd452..a60c8e814654e7e3509172d6daac7259d2233cf2 100644 (file)
@@ -1,13 +1,17 @@
 
-fn main() -> io::Result {
+use z3_treefoil::*;
+
+fn main() -> io::Result<()> {
   let mut o = io::stdout().lock();
   for shape in read_vertices() {
     for vx in shape {
       for c in vx {
         write!(o, "{}", c)?;
       }
-      write!(o, ",", c)?;
+      write!(o, ",")?;
     }
     write!(o, "\n")?;
   }
+
+  Ok(())
 }
index 6821d14d29745a442cae843d60cc5d37c572355b..07f20b17cf54a7e5c7f05e7b21d5266b05a8d7dd 100644 (file)
@@ -1,6 +1,7 @@
 //
 
 pub use std::io;
+pub use std::io::Write as _;
 
 pub fn default<T: Default>() -> T { Default::default() }
 
@@ -8,16 +9,16 @@ pub const DIM: usize = 3;
 pub type Coord = i8;
 pub type Point = [Coord; DIM];
 
-pub fn read_vertices() -> impl Iterator<Itme=Vec<Point>> {
+pub fn read_vertices() -> impl Iterator<Item=Vec<Point>> {
   io::stdin().lines().map(|l| {
     let l = l.unwrap();
-    let mut current = default();
+    let mut current: Point = default();
     l.chars().map(|cx| {
       let cl = cx.to_ascii_lowercase();
-      let d = if cx == cl { -1 } else { +1 };
-      let i = cl as i8 - 'x';
+      let d = if cx == cl { -1 } else { 1 };
+      let i = cl as usize - 'x' as usize;
       current[i] += d;
       current
     }).collect()
-  }
+  })
 }