#!/usr/bin/ruby @fibonaccis = {} def fibonacci(n) if @fibonaccis[n] then @fibonaccis[n] elsif n == 0 then 0 elsif n == 1 then 1 else @fibonaccis[n] = fibonacci(n-2) + fibonacci(n-1) end end (1..500).each do |i| puts "F(#{i}) = #{fibonacci(i)}" end