Skip to content

Instantly share code, notes, and snippets.

@everton
Created April 6, 2011 13:45
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everton/905662 to your computer and use it in GitHub Desktop.
Save everton/905662 to your computer and use it in GitHub Desktop.
Weird way to say Bhaskara in Ruby (or "((-b).± √ Δ(a, b, c))" / (2 * a) as a valid Ruby expression)
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
def √(n)
Math::sqrt(n)
end
class Numeric
def ±(n)
r = [self + n, self - n]
def r./(n)
[first / n, last / n]
end
r
end
end
def Δ(a, b, c)
b**2 - (4 * a * c)
end
def roots(a, b, c)
((-b).± √ Δ(a, b, c)) / (2 * a)
end
# x² -5x + 6
puts roots 1, -5, 6
@timotta
Copy link

timotta commented Apr 7, 2011

muito foda

@evertonfraga
Copy link

iradão, mano

@demetriusnunes
Copy link

bonito

@stockrt
Copy link

stockrt commented Apr 8, 2011

bacana

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment