Skip to content

Instantly share code, notes, and snippets.

@lune-sta
Created August 22, 2012 23:46
Show Gist options
  • Select an option

  • Save lune-sta/3430643 to your computer and use it in GitHub Desktop.

Select an option

Save lune-sta/3430643 to your computer and use it in GitHub Desktop.
Project Euler 33
ans = Rational(1, 1)
(1..9).each do |a|
(1...a).each do |b|
(1..9).each do |c|
d = Rational(b,a)
if Rational(b*10+c, a*10+c) == d ||
Rational(b*10+c, a+c*10) == d ||
Rational(b+c*10, a*10+c) == d ||
Rational(b+c*10, a+c*10) == d
ans *= d
end
end
end
end
puts ans.denominator # 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment