Created
April 2, 2013 05:03
-
-
Save kpuputti/5290058 to your computer and use it in GitHub Desktop.
SICP exercise 1.10 in Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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