Skip to content

Commit

Permalink
update fulladder example to use the tick return value
Browse files Browse the repository at this point in the history
  • Loading branch information
dopsi committed Aug 19, 2019
1 parent f94cdf9 commit c377245
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions examples/fulladder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit c377245

Please sign in to comment.