-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(ns sicp.chapter-1.ex-1-10) | ||
|
||
; Exercise 1.10 | ||
; The following procedure computes a mathematical function called 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))))) | ||
|
||
; What are the values of the following expressions? | ||
(A 1 10) | ||
(A 2 4) | ||
(A 3 3) | ||
|
||
; Consider the following procedures, where A is the procedure defined above: | ||
(defn f [n] (A 0 n)) | ||
(defn g [n] (A 1 n)) | ||
(defn h [n] (A 2 n)) | ||
(defn k [n] (* 5 n n)) | ||
|
||
; Give concise mathematical definitions for the functions computed | ||
; by the procedures f, g, and h for positive integer values of n. | ||
; For example, (k n) computes 5*n^2. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(ns sicp.chapter-1.ex-1-10-test | ||
(:require [clojure.test :refer :all] | ||
[sicp.chapter-1.ex-1-10 :refer [A f g h k]])) | ||
|
||
(deftest A-test | ||
(is (= 1024 (A 1 10))) | ||
(is (= 65536 (A 2 4))) | ||
(is (= 65536 (A 3 3))) | ||
|
||
(is (= 6 (f 3))) | ||
(is (= 8 (g 3))) | ||
(is (= 16 (h 3))) | ||
(is (= 45 (k 3)))) |