diff options
Diffstat (limited to 'examples/13.pry')
| -rw-r--r-- | examples/13.pry | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/13.pry b/examples/13.pry new file mode 100644 index 0000000..839caef --- /dev/null +++ b/examples/13.pry @@ -0,0 +1,44 @@ +import "!stdlib.pry"; + +let main = () => i64 { + /* Iterative Fibonacci using while loop. */ + let fibonacci_iter = (n: i64) => i64 { + let a = 0; + let b = 1; + let i = 0; + while i < n { + let temp = b; + b = a + b; + a = temp; + i = i + 1; + }; + return a; + }; + + /* Recursive GCD using Euclid's algorithm. */ + let gcd = (a: i64, b: i64) => i64 { + if b == 0 { + return a; + }; + return gcd(b, a % b); + }; + + let fib_val = fibonacci_iter(10); + printf("%d\n", fib_val); + + let gcd_val = gcd(48, 18); + printf("%d\n", gcd_val); + + return 0; +}; + +/* + +Expected stdout: + +55 +6 + +Expected return: 0 + +*/ |