Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fact n = product [1..n]
- gcd' a 0 = a
- gcd' a b = gcd' b (a `mod` b)
- sqr x = x*x
- isPrime 2 = True
- isPrime x = x > 0 && odd x && primeIter x 3
- where primeIter x y = if sqr y > x
- then True
- else x `mod` y /= 0 && primeIter x (y+2)
- revInt x = iter x 0
- where iter 0 res = res
- iter x acc = iter (x `div` 10) (acc * 10 + x `mod` 10)
- solveSqr a b c = if d<0
- then []
- else if d == 0
- then [(-b)/(2*a)]
- else [((-b)-(sqrt d))/(2*a),((-b)+(sqrt d))/(2*a)]
- where d = b*b - 4*a*c
- maxSolution a b c = case solution of
- [] -> error "D<0!"
- otherwise -> maximum solution
- where solution = solveSqr a b c
- root::(Double -> Double) -> Double -> Double -> Double -> Double
- root f a b eps = if b - a < eps
- then m
- else if f m == 0 then m
- else if f a * f m > 0
- then root f m b eps
- else root f a m eps
- where m = (b + a)/2
Advertisement
Add Comment
Please, Sign In to add comment