-
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
Denis Smet
committed
Oct 15, 2023
1 parent
68461c4
commit 224b567
Showing
3 changed files
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
(ns sicp.chapter-1.ex-1-13) | ||
|
||
; Exercise 1.13 | ||
; Prove that Fib(n) is the closest integer to φn/5⎯√, where φ=(1+5⎯√)/2. | ||
; Hint: Let ψ=(1−5⎯√)/2. | ||
; Use induction and the definition of the Fibonacci numbers (see 1.2.2) to prove that Fib(n)=(φn−ψn)/5⎯√ | ||
|
||
; Skipped. I'm too young for higher math. |
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,24 @@ | ||
(ns sicp.chapter-1.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. | ||
; What are the orders of growth of the space and number of steps used by this process as the amount to be changed increases? | ||
|
||
(defn first-denomination | ||
[type-of-coins] | ||
(cond (= type-of-coins 1) 1 | ||
(= type-of-coins 2) 5 | ||
(= type-of-coins 3) 10 | ||
(= type-of-coins 4) 25 | ||
(= type-of-coins 5) 50)) | ||
|
||
(defn change | ||
[amount type-of-coins] | ||
(cond (= amount 0) 1 | ||
(or (< amount 0) (= type-of-coins 0)) 0 | ||
:else (+ (change amount (- type-of-coins 1)) | ||
(change (- amount (first-denomination type-of-coins)) type-of-coins)))) | ||
|
||
(defn money-change | ||
[amount] | ||
(change amount 5)) |
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,8 @@ | ||
(ns sicp.chapter-1.ex-1-14-test | ||
(:require [clojure.test :refer :all] | ||
[sicp.chapter-1.ex-1-14 :refer [money-change]])) | ||
|
||
(deftest count-change-test | ||
(is (= 1 (money-change 1))) | ||
(is (= 4 (money-change 10))) | ||
(is (= 292 (money-change 100)))) |