Skip to content

Instantly share code, notes, and snippets.

@veelenga
Last active September 7, 2018 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veelenga/754789e02a64cb5c5cd85d83bdcb96c1 to your computer and use it in GitHub Desktop.
Save veelenga/754789e02a64cb5c5cd85d83bdcb96c1 to your computer and use it in GitHub Desktop.
require "big/big_rational"
def root(n, acc = BigRational.new(2))
base = ->(n : BigRational) { 2 + n.inv }
n.times { acc = base.call(acc) }
1 + acc.inv
end
puts (1..999).map { |n| root(n) }.map { |r| [r.numerator.digits.size, r.denominator.digits.size] }.count { |(n, d)| n > d }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment