list up rational numbers p such that sqrt(p), sqrt (p - 5), sqrt (p + 5) are all rational.
*Main> take 2 answer
[1681 % 144,11183412793921 % 2234116132416]| answer = | |
| map | |
| conversion | |
| (filter | |
| (\(x, y, z) -> test x y) | |
| pythagorean_triples) | |
| conversion :: (Integer, Integer, Integer) -> Rational | |
| conversion (x, y, z) = | |
| toRational (z * z) / (toRational (4 * x * y) / toRational 10) | |
| test :: Integer -> Integer -> Bool | |
| test x y = | |
| (w `mod` 10) == 0 && | |
| is_squre ( | |
| floor ((fromInteger w) / 10)) | |
| where | |
| w = x * y | |
| pythagorean_triples = | |
| filter | |
| (\(x, y, z) -> gcd x y == 1) | |
| [(m * m - n * n, 2 * m * n, m * m + n * n) | m <- [1..], n <- [2..m-1]] | |
| is_squre :: Integer -> Bool | |
| is_squre a = | |
| a == (floor . sqrt . fromInteger) a ^ 2 |