#!/usr/bin/ruby #works for fairly large (>10000) arguments #with this non-recursive version, you don't run out of stack as quickly #but are still limited my memory and swap for the array $cache = [0,1,1,2,3,5,8,13,21,34,55,89] def fib(n) if ($cache[n] != nil) $cache[n] else for p in 12..n $cache[p] = $cache[p - 1] + $cache[p - 2] end $cache[n] end end for inval in ARGV int_in = Integer(inval) print(fib(int_in), "\n") end