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
square :: Integer -> Integer | |
square x = x * x | |
quad :: Integer -> Integer | |
quad x = square (square x) |
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
greater :: (Integer, Integer) -> Integer | |
greater (a, b) = if a > b then a else b |
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
square :: Float -> Float | |
square x = x * x | |
areaOfCircle :: Float -> Float | |
areaOfCircle r = (22 / 7) * square r |
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
(define (sum-square-of-larger-two x y z) | |
(cond ((and (< x y) (< x z)) (+ (* y y) (* z z))) | |
((and (< y x) (< y z)) (+ (* x x) (* z z))) | |
(else (+ (* x x) (* y y))))) |
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
(define (a-plus-abs-b a b) | |
((if (> b 0) + -) a b)) |
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
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 3)))) | |
(* 3 (- 6 2) (- 2 7))) |
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
(define (square-root2 x) | |
(sqrt-iter2 1.0 x x)) | |
(define (sqrt-iter2 prev-guess guess x) | |
(if (good-enough?2 prev-guess guess) | |
guess | |
(sqrt-iter2 guess (improve guess x) x))) | |
(define (good-enough?2 prev-guess guess) | |
(< (abs (/ (- prev-guess guess) prev-guess)) 0.001)) |
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
(define (cube-root x) | |
(cube-root-iter x x 1.0)) | |
(define (cube-root-iter x prev-guess guess) | |
(if (good-enough?2 prev-guess guess) guess | |
(cube-root-iter x guess (improve3 x guess)))) | |
(define (improve3 x guess) | |
(/ (+ (/ x (square guess)) guess guess) 3)) |
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
(define (square-root x) | |
(define (good-enough? guess x) | |
(< (abs (- (square guess) x)) 0.001)) | |
(define (improve guess x) | |
(average guess (/ x guess))) | |
(define (sqrt-iter guess x) | |
(if (good-enough? guess x) | |
guess | |
(sqrt-iter (improve guess x) x))) | |
(sqrt-iter 1.0 x)) |
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
(define (square-root x) | |
(define (good-enough? guess) | |
(< (abs (- (square guess) x)) 0.001)) | |
(define (improve guess) | |
(average guess (/ x guess))) | |
(define (sqrt-iter guess) | |
(if (good-enough? guess) | |
guess | |
(sqrt-iter (improve guess)))) | |
(sqrt-iter 1.0)) |
OlderNewer