solution to problem 57

master
Evan Hemsley 2016-09-06 10:23:54 -07:00
parent d2c5301000
commit d496e33cc1
1 changed files with 17 additions and 0 deletions

17
ruby/euler057.rb Normal file
View File

@ -0,0 +1,17 @@
require_relative 'euler'
def root_two_expansion(iterations)
1 + Rational(1,decimal_expansion(iterations))
end
def decimal_expansion(iterations)
if iterations == 0
return 2
else
return 2 + Rational(1,decimal_expansion(iterations - 1))
end
end
def solution
(0..999).map { |n| root_two_expansion(n) }.count { |r| r.numerator.to_digit_list.count > r.denominator.to_digit_list.count }
end