Skip to content

Instantly share code, notes, and snippets.

@mame mame/gist:6828520
Created Oct 4, 2013

Embed
What would you like to do?
# 0 < A < B < 1 を仮定
lower, upper = 0, 1
loop do
m = Rational(lower.numerator + upper.numerator, lower.denominator + upper.denominator)
case
when m < A then lower = m
when B < m then upper = m
else p [:found, m]; exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.