Last active
December 24, 2015 15:39
-
-
Save notogawa/6822624 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- AをaにBをbにeps近似で,めんどうなので 0 < a, 0 < b に限定するけど | |
innerQ :: Rational -> Rational -> Rational | |
innerQ a b | a > b = innerQ b a | |
innerQ a b = head $ [1 .. d 1] >>= f 1 where | |
-- マジメにやるなら2分探索とか | |
d n | 1 / n < b - a = n | otherwise = d (n+1) | |
f n x | b < n / x = [] | |
| a < n / x && n / x < b = [n / x] -- 近似時のeps分も入れれば確実にAとBの間に入る | |
| n / x < a = f (n+1) x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment