Public
Script
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { lisp } from "https://esm.town/v/zackoverflow/lisp";
export let lispFib = lisp(`
(defun fib (x)
(if (<= x 1)
x
(defun impl (i n-1 n-2)
(if (= x i)
(+ n-1 n-2)
(impl (+ i 1) (+ n-1 n-2) n-1)))
(impl 2 1 0)))
(assert-eq 0 (fib 0))
(assert-eq 1 (fib 1))
(assert-eq 1 (fib 2))
(assert-eq 2 (fib 3))
(assert-eq 3 (fib 4))
(assert-eq 5 (fib 5))
(assert-eq 8 (fib 6))
(assert-eq 13 (fib 7))
`);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023