Skip to content

Commit

Permalink
Minor fixes code style (#158)
Browse files Browse the repository at this point in the history
* Correct indentation and rearrange required namespaces

Changes implemented in this commit primarily involve code's visual indentations and the arrangement of namespaces in scripts from chapter 1 and chapter 2 for better readability. No changes were made to the logic of the code, ensuring that the programs function as previously intended.

* Remove unnecessary whitespace in book_2_3.clj

An unnecessary whitespace following the huffman-message-encoded definition in book_2_3.clj was removed. This cleanup is part of ongoing efforts to improve the readability and maintainability of the code.
  • Loading branch information
SmetDenis authored Feb 9, 2024
1 parent 05a9af5 commit f41f63a
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/sicp/chapter_1/part_3/ex_1_38.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
(if (= i 1)
1
(if (> (rem (- i 2) 3) 0)
1 ; Each second and third values
(* 2 (+ (/ (- i 2) 3) 1))))) ; 2 * ( ( (i-2)/3) + 1)
1 ; Each second and third values
(* 2 (+ (/ (- i 2) 3) 1))))) ; 2 * ( ( (i-2)/3) + 1)
k))
4 changes: 2 additions & 2 deletions src/sicp/chapter_2/part_2/ex_2_45.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
(fn [painter n]
(if (= n 0)
painter
(let [smaller ((split primary secondary) painter (dec n))
primary-split (primary painter smaller)
(let [smaller ((split primary secondary) painter (dec n))
primary-split (primary painter smaller)
secondary-split (secondary smaller smaller)]
(primary primary-split secondary-split)))))

Expand Down
1 change: 0 additions & 1 deletion src/sicp/chapter_2/part_3/book_2_3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@
1 1 1 ; C
0)) ; A
(def huffman-message-encoded '(:A :D :A :B :B :C :A))

(def huffman-A '(0))
(def huffman-B '(1 0))
(def huffman-C '(1 1 1))
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_15_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[sicp.chapter-1.part-2.ex-1-15 :refer [sine]]))

(deftest sine-test
(is (= -0.39980345741334 (sine 12.15)))) ; 5 times, O(log3(n))
(is (= -0.39980345741334 (sine 12.15)))) ; 5 times, O(log3(n))
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_20_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[sicp.chapter-1.part-2.ex-1-20 :refer [gcd]]))

(deftest gcd-test
(is (= 2 (gcd 206 40)))) ; 4 times
(is (= 2 (gcd 206 40)))) ; 4 times
2 changes: 1 addition & 1 deletion test/sicp/chapter_2/part_2/ex_2_33_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns sicp.chapter-2.part-2.ex-2-33-test
(:require
[clojure.test :refer [deftest is]]
[sicp.chapter-2.part-2.ex-2-33 :refer [my-map my-length my-append]]))
[sicp.chapter-2.part-2.ex-2-33 :refer [my-append my-length my-map]]))

(deftest my-map-test
(is (= '(1 2 3) (my-map inc '(0 1 2)))))
Expand Down
12 changes: 6 additions & 6 deletions test/sicp/chapter_2/part_2/ex_2_43_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
[sicp.chapter-2.part-2.ex-2-43 :refer [queens-2-42 queens-2-43]]))

(deftest queens-2-42-test
(is (= 10 (count (queens-2-42 5)))) ; Elapsed time: 6.745917 msecs
(is (= 04 (count (queens-2-42 6)))) ; Elapsed time: 4.257555 msecs
(is (= 40 (count (queens-2-42 7))))) ; Elapsed time: 3.833679 msecs
(is (= 10 (count (queens-2-42 5)))) ; Elapsed time: 6.745917 msecs
(is (= 04 (count (queens-2-42 6)))) ; Elapsed time: 4.257555 msecs
(is (= 40 (count (queens-2-42 7))))) ; Elapsed time: 3.833679 msecs

(deftest queens-2-43-test
(is (= 10 (count (queens-2-43 5)))) ; Elapsed time: 4.883081 msecs
(is (= 04 (count (queens-2-43 6)))) ; Elapsed time: 7.733293 msecs
(is (= 40 (count (queens-2-43 7))))) ; Elapsed time: 6.069276 msecs
(is (= 10 (count (queens-2-43 5)))) ; Elapsed time: 4.883081 msecs
(is (= 04 (count (queens-2-43 6)))) ; Elapsed time: 7.733293 msecs
(is (= 40 (count (queens-2-43 7))))) ; Elapsed time: 6.069276 msecs

; The exercise's method requires O(n^n) recursive calls (instead of O(n))
; exponentially increasing time resource use.
2 changes: 1 addition & 1 deletion test/sicp/chapter_2/part_2/ex_2_49_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns sicp.chapter-2.part-2.ex-2-49-test
(:require
[clojure.test :refer [deftest is]]
[sicp.chapter-2.part-2.ex-2-49 :refer [outline-painter x-painter diamond-painter]]))
[sicp.chapter-2.part-2.ex-2-49 :refer [diamond-painter outline-painter x-painter]]))

; I don't know to test it properly...

Expand Down

0 comments on commit f41f63a

Please sign in to comment.