Skip to content

Instantly share code, notes, and snippets.

@juven
Created December 9, 2013 14:35
Show Gist options
  • Save juven/7873085 to your computer and use it in GitHub Desktop.
Save juven/7873085 to your computer and use it in GitHub Desktop.
clj-demo.scip-1-1-7.clj
(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))
@ethanfu
Copy link

ethanfu commented Dec 9, 2013

个人感觉还真不如lisp写出来的更容易让人理解似的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment