fork download
  1. def fibonacci(termo)
  2. return [] if termo == 0
  3. return [0] if termo == 1
  4. return [0, 1] if termo == 2
  5. lista = fibonacci(termo - 1)
  6. lista << lista[-2] + lista[-1]
  7. return lista
  8. end
  9. print fibonacci(10)
  10.  
  11. #https://pt.stackoverflow.com/q/336649/101
Success #stdin #stdout 0s 28216KB
stdin
Standard input is empty
stdout
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]