Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
# 0 < A < B を仮定
lower_num, lower_den = 0, 1
upper_num, upper_den = 1, 0
loop do
m_num = lower_num + upper_num
m_den = lower_den + upper_den
case
when m_num < A * m_den then lower_num, lower_den = m_num, m_den
when B * m_den < m_num then upper_num, upper_den = m_num, m_den
else p [:found, Rational(m_num, m_den)]
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.