Skip to content

Instantly share code, notes, and snippets.

@kpuputti
Created April 2, 2013 05:03
Show Gist options
  • Save kpuputti/5290058 to your computer and use it in GitHub Desktop.
Save kpuputti/5290058 to your computer and use it in GitHub Desktop.
SICP exercise 1.10 in Clojure
; compute the Ackermann's function
(defn A [x y]
(cond (= y 0) 0
(= x 0) (*' 2 y)
(= y 1) 2
:else (A (- x 1)
(A x (- y 1)))))
; f(x) = 2x
(defn f [n]
(A 0 n))
; g(n) = 2^n
(defn g [n]
(A 1 n))
; h(n) = ?
(defn h [n]
(A 2 n))
; (A 2 n)
; (A 1 (A 2 (- n 1)))
; k(n) = 5n^2
(defn k [n]
(* 5 n n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment