#!/usr/bin/ruby # Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) # # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to # Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, # 94105, USA. def fibonacci(n) return -1 if (n <= 0); return 1 if (n <= 2); return fibonacci(n-1) + fibonacci(n-2) end if ARGV.length != 1 $stderr.printf "Usage:\n\t%s (n-th fibonacci # to calculate)\n", $0 exit -1 end printf "fibonacci(%s): %d\n", ARGV[0], fibonacci(ARGV[0].to_i)