Skip to content

Instantly share code, notes, and snippets.

@gtcarlos
Created November 30, 2012 02:38
Show Gist options
  • Save gtcarlos/4173443 to your computer and use it in GitHub Desktop.
Save gtcarlos/4173443 to your computer and use it in GitHub Desktop.
Exercício APDA (INCOMPLETO)
MAX = 8
def fib(n)
return n if (0..1).include? n
fib(n-1) + fib(n-2) if n > 1
end
def fatorial(n)
return n <= 1 ? 1 : n * fatorial(n-1)
end
def num_primo(n)
return case n
when 1 then 1
when 2 then 2
when 3 then 3
when 4 then 5
when 5 then 7
when 6 then 11
when 7 then 13
when 8 then 17
end
end
def root(n, primo)
return n % 2 ? (((n + primo) ** ((1.0/(primo + fib(n)))* n)) / fatorial(fib(n))) : (((n - primo) ** ((1.0/(primo + fib(n)))* n)) / fatorial(fib(n)))
end
print "Digite o valor de x: "
x = gets
x = x.to_i
MAX.times do |i|
primo = num_primo(i + 1)
puts root(x, primo)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment