Skip to content

Instantly share code, notes, and snippets.

@notogawa
Last active December 24, 2015 15:39
Show Gist options
  • Save notogawa/6822624 to your computer and use it in GitHub Desktop.
Save notogawa/6822624 to your computer and use it in GitHub Desktop.
-- 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