Skip to content

Instantly share code, notes, and snippets.

@tyler
Created June 3, 2010 03:25
Show Gist options
  • Save tyler/423401 to your computer and use it in GitHub Desktop.
Save tyler/423401 to your computer and use it in GitHub Desktop.
def even?(n)
n % 2 == 0
end
def fast_mult(b, n)
a = 0
while n > 0
if even?(n)
n /= 2
b *= 2
else
n -= 1
a += b
end
end
a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment