Created
March 31, 2010 20:12
-
-
Save valyagolev/350819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import List (sortBy) | |
isInteger :: Rational -> Bool | |
isInteger x = (toRational (truncate x)) == x | |
isQuad :: (Floating a, Real a) => a -> Bool | |
isQuad x = isInteger (toRational (sqrt x)) | |
findMinX :: (Floating a, Real a, Enum a) => a -> a | |
findMinX d = if (isQuad d) then -1 else (head $ filter goes [2..]) | |
where | |
goes x = isQuad ((x*x-1)/d) | |
allXs = map (\x -> [findMinX x, x]) [1..1000] | |
maxim = head $ sortBy (\y x -> compare (head x) (head y)) allXs | |
main = do | |
mapM print allXs | |
print maxim | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment