Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sub folders for parts of chapters #18

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-1)
(ns sicp.chapter-1.part_1.ex-1-1)

; Exercise 1.1
; Below is a sequence of expressions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter_1.ex-1-2)
(ns sicp.chapter_1.part_1.ex-1-2)

; Exercise 1.2
; Translate the following expression into prefix form:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-3)
(ns sicp.chapter-1.part_1.ex-1-3)

; Exercise 1.3
; Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-4)
(ns sicp.chapter-1.part_1.ex-1-4)

; Exercise 1.4
; Observe that our model of evaluation allows for combinations whose operators are compound expressions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-5)
(ns sicp.chapter-1.part_1.ex-1-5)

; Exercise 1.5
; Ben Bitdiddle has invented a test to determine whether the interpreter he is faced with is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-6)
(ns sicp.chapter-1.part_1.ex-1-6)

; Exercise 1.6
; Alyssa P. Hacker doesn’t see why if needs to be provided as a special form.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-7)
(ns sicp.chapter-1.part_1.ex-1-7)

; Exercise 1.7
; The `good-enough?` test used in computing square roots will not be very effective
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-8)
(ns sicp.chapter-1.part_1.ex-1-8)

; Exercise 1.8
; Newton’s method for cube roots is based on the fact that if y
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-10)
(ns sicp.chapter-1.part_2.ex-1-10)

; Exercise 1.10
; The following procedure computes a mathematical function called Ackermann’s function.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-11)
(ns sicp.chapter-1.part_2.ex-1-11)

; Exercise 1.11
; A function f is defined by the rule that f(n)=n
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-12)
(ns sicp.chapter-1.part_2.ex-1-12)

; Exercise 1.12
; The following pattern of numbers is called Pascal’s triangle.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-13)
(ns sicp.chapter-1.part_2.ex-1-13)

; Exercise 1.13
; Prove that Fib(n) is the closest integer to φn/5⎯√, where φ=(1+5⎯√)/2.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-14)
(ns sicp.chapter-1.part_2.ex-1-14)

; Exercise 1.14
; Draw the tree illustrating the process generated by the count-change procedure of 1.2.2 in making change for 11 cents.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex_1_15)
(ns sicp.chapter-1.part_2.ex_1_15)

; Exercise 1.15
; The sine of an angle (specified in radians) can be computed by making use of the approximation sinx≈x
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-16)
(ns sicp.chapter-1.part_2.ex-1-16)

; Exercise 1.16
; Design a procedure that evolves an iterative exponentiation process
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-17)
(ns sicp.chapter-1.part_2.ex-1-17)

; Exercise 1.17
; The exponentiation algorithms in this section are based on performing exponentiation by means of repeated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns sicp.chapter-1.ex-1-18
(:require [sicp.chapter-1.ex-1-16 :refer [expt]]))
(ns sicp.chapter-1.part_2.ex-1-18
(:require [sicp.chapter-1.part_2.ex-1-16 :refer [expt]]))

; Exercise 1.18
; Using the results of Exercise 1.16 and Exercise 1.17, devise a procedure that generates an iterative
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-19)
(ns sicp.chapter-1.part_2.ex-1-19)

; Exercise 1.19.
;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-20)
(ns sicp.chapter-1.part_2.ex-1-20)

; Exercise 1.20
; The process that a procedure generates is of course dependent on the rules used by the interpreter.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-21)
(ns sicp.chapter-1.part_2.ex-1-21)

; Exercise 1.21
; Use the smallest-divisor procedure to find the smallest divisor of each of the following numbers:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-22)
(ns sicp.chapter-1.part_2.ex-1-22)

; Exercise 1.22
; Most Lisp implementations include a primitive called runtime that returns an integer that specifies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns sicp.chapter-1.ex-1-9)
(ns sicp.chapter-1.part_2.ex-1-9)

; Exercise 1.9
; Each of the following two procedures defines a method for adding two positive integers
Expand Down
6 changes: 0 additions & 6 deletions test/sicp/chapter_1/ex_1_18_test.clj

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-3-test
(ns sicp.chapter-1.part_1.ex-1-3-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-3 :refer [sum-larger-numbers-square]]))
[sicp.chapter-1.part_1.ex-1-3 :refer [sum-larger-numbers-square]]))

(deftest sum-larger-numbers-square-test
(is (= 2 (sum-larger-numbers-square 1 1 1)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-4-test
(ns sicp.chapter-1.part_1.ex-1-4-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-4 :refer [a-plus-abs-b]]))
[sicp.chapter-1.part_1.ex-1-4 :refer [a-plus-abs-b]]))

(deftest a-plus-abs-b-test
(is (= 2 (a-plus-abs-b 1 1)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-5-test
(ns sicp.chapter-1.part_1.ex-1-5-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-5 :refer [test_1_5 p]]))
[sicp.chapter-1.part_1.ex-1-5 :refer [test_1_5 p]]))

(deftest test_1_5-test
; Normal: Operand "p" will not be evaluated until it's needed by some primitive operation. So result is 0.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-6-test
(ns sicp.chapter-1.part_1.ex-1-6-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-6 :refer [sqrt-iter sqrt-iter-new-if]]))
[sicp.chapter-1.part_1.ex-1-6 :refer [sqrt-iter sqrt-iter-new-if]]))

(deftest sqrt-iter-test
; Expected
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-7-test
(ns sicp.chapter-1.part_1.ex-1-7-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-7 :refer [sqrt-iter sqrt-iter-v2]]))
[sicp.chapter-1.part_1.ex-1-7 :refer [sqrt-iter sqrt-iter-v2]]))

(deftest sqrt-iter-test
; 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-8-test
(ns sicp.chapter-1.part_1.ex-1-8-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-8 :refer [cube-root-iter]]))
[sicp.chapter-1.part_1.ex-1-8 :refer [cube-root-iter]]))

(deftest cube-root-iter-test
; 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-10-test
(ns sicp.chapter-1.part_2.ex-1-10-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-10 :refer [A f g h k]]))
[sicp.chapter-1.part_2.ex-1-10 :refer [A f g h k]]))

(deftest A-test
(is (= 1024 (A 1 10)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-11-test
(ns sicp.chapter-1.part_2.ex-1-11-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-11 :refer [f f-v2]]))
[sicp.chapter-1.part_2.ex-1-11 :refer [f f-v2]]))

(deftest f-test
; ~ O(3^n)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-12-test
(ns sicp.chapter-1.part_2.ex-1-12-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-12 :refer [pascal]]))
[sicp.chapter-1.part_2.ex-1-12 :refer [pascal]]))

(deftest pascal-test
(is (= 1 (pascal 1 1)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-14-test
(ns sicp.chapter-1.part_2.ex-1-14-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-14 :refer [money-change]]))
[sicp.chapter-1.part_2.ex-1-14 :refer [money-change]]))

(deftest count-change-test
(is (= 1 (money-change 1)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex_1_15-test
(ns sicp.chapter-1.part_2.ex_1_15-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex_1_15 :refer [sine]]))
[sicp.chapter-1.part_2.ex_1_15 :refer [sine]]))

(deftest sine-test
(is (= -0.39980345741334 (sine 12.15))) ; 5 times, O(log3(n))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-16-test
(ns sicp.chapter-1.part_2.ex-1-16-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-16 :refer [expt]]))
[sicp.chapter-1.part_2.ex-1-16 :refer [expt]]))

(deftest expt-test
(is (= 1 (expt 1 2)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-17-test
(ns sicp.chapter-1.part_2.ex-1-17-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-17 :refer [multi multi-fast]]))
[sicp.chapter-1.part_2.ex-1-17 :refer [multi multi-fast]]))

(deftest multi-test
(time (is (= 2 (multi 1 2)))) ; "Elapsed time: 2.383128 msecs"
Expand Down
6 changes: 6 additions & 0 deletions test/sicp/chapter_1/part_2/ex_1_18_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns sicp.chapter-1.part_2.ex-1-18-test
(:require [clojure.test :refer :all])
(:require [sicp.chapter-1.part_2.ex-1-18 :refer [mult]]))

(deftest mult-test
(is (= 0 (mult 0 19))))
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-19-test
(ns sicp.chapter-1.part_2.ex-1-19-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-19 :refer [fib fib-v2]]))
[sicp.chapter-1.part_2.ex-1-19 :refer [fib fib-v2]]))

(deftest fib-test
(is (= 1 (fib 1)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-20-test
(ns sicp.chapter-1.part_2.ex-1-20-test
(:require [clojure.test :refer :all])
(:require [sicp.chapter-1.ex-1-20 :refer [gcd]]))
(:require [sicp.chapter-1.part_2.ex-1-20 :refer [gcd]]))

(deftest gcd-test
(is (= 2 (gcd 206 40))) ; 4 times
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-21-test
(ns sicp.chapter-1.part_2.ex-1-21-test
(:require [clojure.test :refer :all])
(:require [sicp.chapter-1.ex-1-21 :refer [smallest-divisor]]))
(:require [sicp.chapter-1.part_2.ex-1-21 :refer [smallest-divisor]]))

(deftest smallest-divisor-test
(is (= 199 (smallest-divisor 199)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-22-test
(ns sicp.chapter-1.part_2.ex-1-22-test
(:require [clojure.test :refer :all])
(:require [sicp.chapter-1.ex-1-22 :refer [find-primes]]))
(:require [sicp.chapter-1.part_2.ex-1-22 :refer [find-primes]]))

(deftest find-primes-test
(is (= 5 (find-primes 1 5)))) ; Change arguments and see the output
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns sicp.chapter-1.ex-1-9-test
(ns sicp.chapter-1.part_2.ex-1-9-test
(:require [clojure.test :refer :all]
[sicp.chapter-1.ex-1-9 :refer [plus plus-v2]]))
[sicp.chapter-1.part_2.ex-1-9 :refer [plus plus-v2]]))

(deftest plus-test
(is (= 3 (plus 1 2))))
Expand Down