-
Notifications
You must be signed in to change notification settings - Fork 156
/
example_program.cairo
47 lines (38 loc) · 1.12 KB
/
example_program.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
%builtins range_check
from starkware.cairo.common.math import assert_nn
func assert_nn_manual_implementation{range_check_ptr}(a) {
%{
from starkware.cairo.common.math_utils import assert_integer
assert_integer(ids.a)
assert 0 <= ids.a % PRIME < range_check_builtin.bound, f'a = {ids.a} is out of range.'
%}
a = [range_check_ptr];
let range_check_ptr = range_check_ptr + 1;
return ();
}
func fib(first_element, second_element, n) -> (res: felt) {
jmp fib_body if n != 0;
tempvar result = second_element;
return (second_element,);
fib_body:
tempvar y = first_element + second_element;
return fib(second_element, y, n - 1);
}
func evaluate_fib() {
// Call fib(1, 1, 10).
let result: felt = fib(1, 1, 10);
// Make sure the 10th Fibonacci number is 144.
assert result = 144;
return ();
}
func main{range_check_ptr: felt}() {
let x = 64;
tempvar y = 64 * 64;
assert_nn(1);
assert_nn(x);
assert_nn(y);
assert_nn_manual_implementation(1);
assert_nn_manual_implementation(x);
assert_nn_manual_implementation(y);
return ();
}