aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Yoo2022-10-24 23:46:58 +0000
committerJames Yoo2022-10-24 23:46:58 +0000
commit0921d8222bb883ea86d51c7200a865a5e4dbc469 (patch)
tree4af97fddb36c9748c9b051c18312c8b35b6f2013
parent52035dd7c9c0cca23c4df1a0dc178222bd9beb54 (diff)
Adding HtDP version of fibonacci, pre @htdp tags
-rw-r--r--entries/jyoo980/vintage-htdp/fib.rkt17
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))))]))