Created
January 12, 2023 21:17
-
-
Save jido/b27530a41ddfc289889d9cc851eee30b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imported Clojure functions | |
clojure('<=', 2) -> lte | |
clojure('dec', 1) -> dec | |
# Fibonacci function (recursive) | |
# Takes advantage of dodo ability to return more than one result at once | |
fun fib -> n, return, throw | |
( | |
'<='(n, 0) -> zero | |
if (zero) -> | |
return(1, 0) | |
| | |
dec(n) -> k | |
fib(k) -> f1, f2 | |
( | |
add(f1, f2) -> f12 | |
return(f12, f1) | |
) | |
(| e) throw(e) | |
) | |
| fib | |
# Test with a few numbers | |
fib(0) (-> x, y) println("fib(0)=", x) -> | |
fib(1) (-> x, y) println("fib(1)=", x) -> | |
fib(2) (-> x, y) println("fib(2)=", x) -> | |
fib(3) (-> x, y) println("fib(3)=", x) -> | |
fib(4) (-> x, y) println("fib(4)=", x) -> | |
fib(5) (-> x, y) println("fib(5)=", x) -> | |
fib(10) (-> x, y) println("fib(10)=", x) -> | |
fib(100) (-> x, y) println("fib(100)=", x) -> | |
fib(1000) (-> x, y) println("fib(1000)=", x) -> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment