aboutsummaryrefslogtreecommitdiff
path: root/entries/jyoo980/vintage-htdp
diff options
context:
space:
mode:
authorBraxton Hall2022-10-25 00:00:01 +0000
committerGitHub2022-10-25 00:00:01 +0000
commitf8350ce16a8b195f5b886299f0a10e2ade39d327 (patch)
treece2bad285e72ef3d5233c48b22f694dfcf51fcf5 /entries/jyoo980/vintage-htdp
parent8e962516a634c92ed04bcd5961c177629ab055e9 (diff)
parent60d5f5781a05275963543c51389fe46dd0243015 (diff)
Merge pull request #32 from jyoo980/main
Adding vintage HtDP version of Fib
Diffstat (limited to 'entries/jyoo980/vintage-htdp')
-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))))]))