Skip to content

Commit

Permalink
add some example programs
Browse files Browse the repository at this point in the history
  • Loading branch information
Snektron committed Feb 12, 2022
1 parent a242fef commit 5bcfcb7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/fib.par
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fn fib[n: int]: int {
if n < 2 {
return n;
}

var x0 = 0;
var x1 = 1;
while n > 0 {
var tmp = x0 + x1;
x0 = x1;
x1 = tmp;
n = n - 1;
}

return x1;
}
6 changes: 6 additions & 0 deletions examples/gcd.par
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn gcd[a: int, b: int]: int {
if b == 0 {
return a;
}
return gcd[b, a % b];
}
9 changes: 9 additions & 0 deletions examples/sqrt.par
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn sqrt[a: float]: float {
var x = 0.5 * a;
var i = 10;
while i > 0 {
x = 0.5 * (x + a / x);
i = i - 1;
}
return x;
}

0 comments on commit 5bcfcb7

Please sign in to comment.