Skip to content

Instantly share code, notes, and snippets.

@itsmuriuki
Created October 14, 2016 00:09
Show Gist options
  • Save itsmuriuki/175f48fd61b4a415a1b52af5b52a05d3 to your computer and use it in GitHub Desktop.
Save itsmuriuki/175f48fd61b4a415a1b52af5b52a05d3 to your computer and use it in GitHub Desktop.
arra = [1,2,3]
def roots_of_eqn(coeffs)
a = coeffs[0]
b = coeffs[1]
c = coeffs[2]
d = (b * b) - (4 * a * c)
if d <= 0
puts "Its a complex root"
else
e = Math.sqrt(d)
f1 = (-b + e) / (2 * a)
f2 = (-b - e) / (2 * a)
return [f1, f2]
end
end
puts(roots_of_eqn(arra))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment