Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Square Root function
# -*- coding: utf-8 -*-
Sqrt = ->(n) {
guess = n / 2.0
loop do
if (guess**2 - n) < 0.0001
return guess
end
guess = (guess + n/guess) / 2.0
end
}
require 'rspec/given'
require 'given/fuzzy_shortcuts'
describe "sqrt" do
Then { Sqrt.(100) == 10.±(0.0001) }
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.