aboutsummaryrefslogtreecommitdiff
path: root/examples/fib_rec.sloth
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-02-27 07:21:50 -0600
committerCody <cody@codyq.dev>2023-02-27 07:21:50 -0600
commitebfd74ddf0ef6372624ea171e06f8460d0e1351b (patch)
treed59df0e9600a6f2b86b57949048cf990a3e102ae /examples/fib_rec.sloth
parenta653a6602fe5ae5eb4739755db7b34bc92ecdadf (diff)
downloadsloth-ebfd74ddf0ef6372624ea171e06f8460d0e1351b.tar.gz
pain
Diffstat (limited to 'examples/fib_rec.sloth')
-rw-r--r--examples/fib_rec.sloth7
1 files changed, 7 insertions, 0 deletions
diff --git a/examples/fib_rec.sloth b/examples/fib_rec.sloth
new file mode 100644
index 0000000..306bcdf
--- /dev/null
+++ b/examples/fib_rec.sloth
@@ -0,0 +1,7 @@
+## Calculate a specific number in the fibonacci sequence
+fn fib(n: i32) -> i32 {
+ match n {
+ 0 | 1 => n,
+ _ => fib(n - 1) + fib(n - 2),
+ }
+}