Skip to content

Instantly share code, notes, and snippets.

@valyagolev
Created March 31, 2010 20:12
Show Gist options
  • Save valyagolev/350819 to your computer and use it in GitHub Desktop.
Save valyagolev/350819 to your computer and use it in GitHub Desktop.
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