Skip to content

Commit 861cd1e

Browse files
committed
solve chapter 15 exercise 6
1 parent 4b7ab3e commit 861cd1e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ I have also been participating in a [Haskell programming study](<https://gitlab.
182182

183183
### Chapter 15
184184

185-
[15.5.1](ch15/ex1.txt)
186-
[15.5.2](ch15/ex2.txt)
187-
[15.5.3](ch15/ex3.txt)
188-
[15.5.4](ch15/ex4.hs)
189-
[15.5.5](ch15/ex5.hs)
190-
[15.5.6]
185+
[15.9.1](ch15/ex1.txt)
186+
[15.9.2](ch15/ex2.txt)
187+
[15.9.3](ch15/ex3.txt)
188+
[15.9.4](ch15/ex4.hs)
189+
[15.9.5](ch15/ex5.hs)
190+
[15.9.6](ch15/ex6.hs)
191191

192192
### Chapter 16
193193

ch15/ex6.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sqroot :: Double -> Double
2+
sqroot n = snd . head $ dropWhile pred (zip it (tail it))
3+
where
4+
approx = 0.00001
5+
pred (x,y) = abs (x - y) > approx
6+
it = iterate next n
7+
next a = (a + n / a) / 2

0 commit comments

Comments
 (0)