This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quad_eq(eq) | |
alpha = eq[0].to_f | |
beta = eq[1].to_f | |
gamma = equation[2].to_f | |
omega = beta**2 - (4 * alpha * gamma) | |
if omega < 0 | |
print "The equation has no roots" | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No code yet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lsp_range(lsp): | |
if len(lsp) == 1: | |
return [lsp[0]] | |
sm = lsp[0] | |
lg = lsp[0] | |
for i in lsp: | |
if i > lg: | |
lg = i | |
elif i < sm: | |
sm = i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prime?(x) | |
[9] pry(main)* root = square(x, 0.0001) | |
[9] pry(main)* a = 2..(root) | |
[9] pry(main)* a.each do |i| | |
[9] pry(main)* return false if x % i == 0 | |
[9] pry(main)* end | |
[9] pry(main)* true | |
[9] pry(main)* end | |
=> :prime? | |
[10] pry(main)> prime?(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> def square(n, diff) | |
[1] pry(main)* guess = refine(1, n) | |
[1] pry(main)* while (((guess * guess) - n ) .abs > diff) | |
[1] pry(main)* guess = refine(guess, n) | |
[1] pry(main)* end | |
[1] pry(main)* puts guess | |
[1] pry(main)* end | |
=> :square | |
[2] pry(main)> def refine(guess, n) | |
[2] pry(main)* guess = (guess + (n / guess)) / 2.0 |