Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Nth-root/Racket/nth-root.rkt
Normal file
15
Task/Nth-root/Racket/nth-root.rkt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#lang racket
|
||||
|
||||
(define (nth-root number root (tolerance 0.001))
|
||||
(define (acceptable? next current)
|
||||
(< (abs (- next current)) tolerance))
|
||||
|
||||
(define (improve current)
|
||||
(/ (+ (* (- root 1) current) (/ number (expt current (- root 1)))) root))
|
||||
|
||||
(define (loop current)
|
||||
(define next-guess (improve current))
|
||||
(if (acceptable? next-guess current)
|
||||
next-guess
|
||||
(loop next-guess)))
|
||||
(loop 1.0))
|
||||
Loading…
Add table
Add a link
Reference in a new issue