diff options
author | funemy | 2022-10-25 07:14:52 +0000 |
---|---|---|
committer | funemy | 2022-10-25 07:14:52 +0000 |
commit | 998ef837b43203319397f191036a97a5adc42220 (patch) | |
tree | 920558bd60d282c663fd2da1cd4144cac1849a1d /entries/jyoo980/vintage-htdp | |
parent | fdac6c60e115297a58f5b81da0c4b7f18ac758f2 (diff) | |
parent | ce7544a6db594f7d3dfad0d7dc65d01515e57ad6 (diff) |
Merge branch 'main' of github.com:braxtonhall/fib
Diffstat (limited to 'entries/jyoo980/vintage-htdp')
-rw-r--r-- | entries/jyoo980/vintage-htdp/fib.rkt | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/entries/jyoo980/vintage-htdp/fib.rkt b/entries/jyoo980/vintage-htdp/fib.rkt new file mode 100644 index 0000000..697c17b --- /dev/null +++ b/entries/jyoo980/vintage-htdp/fib.rkt @@ -0,0 +1,17 @@ +;; Natural -> Natural +;; given n, produce the nth fibonacci number +(check-expect (fib 0) 0) +(check-expect (fib 1) 1) +(check-expect (fib 2) 1) +(check-expect (fib 7) 13) + +; (define (fib n) 0) ; stub + +;<template from Natural> +(define (fib n) + (cond + [(zero? n) 0] + [else + (if (= n 1) + 1 + (+ (fib (sub1 n)) (fib (- n 2))))])) |