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
1 parent
948ee80
commit 8454c63
Showing
3 changed files
with
29 additions
and
1 deletion.
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,11 @@ | ||
#lang racket/base | ||
(require rackunit) | ||
|
||
;;; BEGIN | ||
{!! $solution !!} | ||
;;; END | ||
|
||
(check-equal? (round (* 1000 (cube-root 8.0))) 2000.0) | ||
(check-equal? (round (* 1000 (cube-root 1000.0))) 10000.0) | ||
(check-equal? (round (* 1000 (cube-root 1000000000.0))) 1000000.0) | ||
(check-equal? (round (* 1000 (cube-root 0.008))) 200.0) |
17 changes: 17 additions & 0 deletions
17
resources/views/exercise/solution_stub/1_8_solution.blade.php
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,17 @@ | ||
(define (sqr x) (* x x)) | ||
|
||
(define (cube x) (* x x x)) | ||
|
||
(define (improve guess x) | ||
(/ (+ (* 2 guess) (/ x (sqr guess))) 3)) | ||
|
||
(define (good-enough? guess x) | ||
(< (abs (- (cube guess) x)) 0.000001)) | ||
|
||
(define (cube-root-iter guess x) | ||
(if (good-enough? guess x) | ||
guess | ||
(cube-root-iter (improve guess x) x))) | ||
|
||
(define (cube-root x) | ||
(cube-root-iter 1.0 x)) |