Haskell Laziness
next :: Double->Double->Double
next n x = (x+n/x)/2
within :: Double -> [Double] -> Double
within eps (a:b:rest) = if abs (a-b) < eps
then b
else within eps (b:rest)
relative :: Double -> [Double] -> Double
relative eps (a:b:rest) = if abs (a/b-1) < eps
then b
else within eps (b:rest)
squareRoot ::Double ->Double ->Double
squareRoot eps n = within eps (iterate (next n) 1.0)
squareRoot2 ::Double ->Double ->Double
squareRoot2 eps n = relative eps (iterate (next n) 1.0)
solutions
fizzBuzz :: [String]
fizzBuzz = map changeFizzbuzz [1..]
where
changeFizzbuzz i
| i `mod` 3 == 0 && i `mod` 5==0 = "FizzBuzz"
| i`mod`3 ==0 = "Fizz"
| i`mod`5 ==0 = "Buzz"
| otherwise = show i