Skip to content

Commit

Permalink
Looped fibonacci (#567)
Browse files Browse the repository at this point in the history
* Rust cache on check

* Fibo looped

* Delete CI upgrade that belongs to another pr
  • Loading branch information
MauroToscano authored Sep 21, 2023
1 parent a190b17 commit 1da50bc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions provers/cairo/cairo_programs/cairo0/fibonacci_5_loop.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

// Looped fibonacci is more efficient
// than calling the fibo function with recursion
// For n = 5, it's 31 steps vs 49 steps
// This is useful to compare with other vms that are not validating the call stack for fibonacci

func main{}() {
tempvar x0 = 0;
tempvar x1 = 1;
tempvar fib_acc = x0 + x1;
tempvar n = 5;
loop:
tempvar x0 = x1;
tempvar x1 = fib_acc;
tempvar fib_acc = x0 + x1;
tempvar n = n - 1;
jmp loop if n != 0;

assert fib_acc = 13;
return ();
}

0 comments on commit 1da50bc

Please sign in to comment.