Skip to content

Instantly share code, notes, and snippets.

@kejadlen
Created December 18, 2012 04:16
Show Gist options
  • Save kejadlen/4324973 to your computer and use it in GitHub Desktop.
Save kejadlen/4324973 to your computer and use it in GitHub Desktop.
Another coding assignment for Tableau.
require 'minitest/autorun'
class TestDiv < MiniTest::Unit::TestCase
def div(x, y)
return 0 if x < y
current = 1
while x - 2 * current * y >= y
current *= 2
end
remainder = x - current * y
current + div(remainder, y)
end
def test_div
100.times do
x = rand(100)
y = rand(100) + 1
assert_equal (x/y), div(x, y)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment