File tree 4 files changed +57
-10
lines changed
4 files changed +57
-10
lines changed Original file line number Diff line number Diff line change 1
1
# ` hello_world `
2
2
3
3
This example is a result of running ` scarb new --no-vcs hello_world ` .
4
+ This template can be both run and tested, try running following commands:
5
+
6
+ ``` shell
7
+ scarb build
8
+ ```
9
+
10
+ ``` shell
11
+ scarb test
12
+ ```
13
+
14
+ ``` shell
15
+ scarb cairo-run --available-gas 200000
16
+ ```
Original file line number Diff line number Diff line change @@ -5,4 +5,4 @@ version = "0.1.0"
5
5
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html
6
6
7
7
[dependencies ]
8
- alexandria_math = { git = " https://github.com/keep-starknet-strange/alexandria.git " }
8
+ # foo = { path = "vendor/foo " }
Original file line number Diff line number Diff line change 1
- use alexandria_math :: fibonacci :: fib;
1
+ fn main () -> felt252 {
2
+ fib (16 )
3
+ }
2
4
3
- fn double_fib (a : felt252 , b : felt252 , n : felt252 ) -> felt252 {
4
- 2 * fib (a , b , n )
5
+ fn fib (mut n : felt252 ) -> felt252 {
6
+ let mut a : felt252 = 0 ;
7
+ let mut b : felt252 = 1 ;
8
+ loop {
9
+ if n == 0 {
10
+ break a ;
11
+ }
12
+ n = n - 1 ;
13
+ let temp = b ;
14
+ b = a + b ;
15
+ a = temp ;
16
+ }
5
17
}
6
18
7
19
#[cfg(test)]
8
20
mod tests {
9
- use super :: double_fib ;
21
+ use super :: fib ;
10
22
11
23
#[test]
12
24
#[available_gas(100000)]
13
25
fn it_works () {
14
- assert (double_fib ( 0 , 1 , 16 ) == 1974 , ' it works!' );
26
+ assert (fib ( 16 ) == 987 , ' it works!' );
15
27
}
16
28
}
Original file line number Diff line number Diff line change @@ -139,10 +139,32 @@ fn mk(
139
139
fsx:: write (
140
140
source_path,
141
141
indoc ! { r#"
142
- fn fib(a: felt252, b: felt252, n: felt252) -> felt252 {
143
- match n {
144
- 0 => a,
145
- _ => fib(b, a + b, n - 1),
142
+ fn main() -> felt252 {
143
+ fib(16)
144
+ }
145
+
146
+ fn fib(mut n: felt252) -> felt252 {
147
+ let mut a: felt252 = 0;
148
+ let mut b: felt252 = 1;
149
+ loop {
150
+ if n == 0 {
151
+ break a;
152
+ }
153
+ n = n - 1;
154
+ let temp = b;
155
+ b = a + b;
156
+ a = temp;
157
+ }
158
+ }
159
+
160
+ #[cfg(test)]
161
+ mod tests {
162
+ use super::fib;
163
+
164
+ #[test]
165
+ #[available_gas(100000)]
166
+ fn it_works() {
167
+ assert(fib(16) == 987, 'it works!');
146
168
}
147
169
}
148
170
"# } ,
You can’t perform that action at this time.
0 commit comments