Skip to content

Instantly share code, notes, and snippets.

@M1nhNV
Created July 12, 2018 10:35
Show Gist options
  • Save M1nhNV/1cc8d4a75e6383758bd79abb26f9a12f to your computer and use it in GitHub Desktop.
Save M1nhNV/1cc8d4a75e6383758bd79abb26f9a12f to your computer and use it in GitHub Desktop.
Ruby
def fibonaci(num)
$i = 0
$s1 = 0
$s2 = 0
$s3 = 0
while $i < $num.to_i do
if ($i <= 1)
$s1 = 1
$s2 = 1
puts 1
else
$s3 = $s2 + $s1
$s1 = $s2
$s2 = $s3
puts $s3;
end
$i += 1
end
end
def quadraticEquation2(a, b, c)
a = a.to_f
b = b.to_f
c = c.to_f
if a == 0
x = b / c
return x
end
x1 = (-b - Math.sqrt(b**2-4*a*c)) / (2*a)
x2 = (-b + Math.sqrt(b**2-4*a*c)) / (2*a)
rs = ['x1' => x1, 'x2' => x2]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment