Created
December 9, 2013 14:35
-
-
Save juven/7873085 to your computer and use it in GitHub Desktop.
clj-demo.scip-1-1-7.clj
This file contains hidden or 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
(ns clj-demo.scip-1-1-7) | |
(:require [clojure.contrib.math :as math])) | |
(defn improve [guess x] | |
(/ (+ guess (/ x guess)) 2)) | |
(defn good-enough? [guess x] | |
(< (math/abs (- (math/expt guess 2) x)) 0.001)) | |
(defn sqrt-iter [guess x] | |
(if (good-enough? guess x) | |
guess | |
(sqrt-iter (improve guess x) x))) | |
(defn sqrt [x] | |
(sqrt-iter 1.0 x)) | |
(println (sqrt 9)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
个人感觉还真不如lisp写出来的更容易让人理解似的