diff --git a/examples/fulladder.rs b/examples/fulladder.rs index b89e775..51ea16e 100644 --- a/examples/fulladder.rs +++ b/examples/fulladder.rs @@ -110,17 +110,29 @@ fn main() { y.replace(triple[1]); c.replace(triple[2]); - for _ in 0..3 { - circuit.tick(); + let mut cycle_count = 0_u32; + while circuit.tick() && cycle_count < 10_u32 { + cycle_count += 1; } + // If the number of required ticks is known, it is possible to use + // a loop with a fixed number of iterations + // ``` + // for _ in 0..3 { + // circuit.tick(); + // } + // ``` + + cycle_count += 1; // To get the correct number of cycles + println!( - "{} + {} + {} = {}{}", + "{} + {} + {} = {}{} (used {} cycles to reach a stable circuit)", triple[0], triple[1], triple[2], cout.value(), - s.value() + s.value(), + cycle_count ); assert_eq!(triple[3], s.value()); assert_eq!(triple[4], cout.value());