gistlib
other ruby categories
fibonacci code snippets in ruby
explain this `fibonacci.sum {| number | number * number }` in ruby
find the nth fibonacci number in ruby
here sum all fibonacci terms that are even: `def fibona(n) return n if n < 2 fib_sequence = [1, 1] (1...n).each do |_| fib_sequence << fib_sequence[-1] + fib_sequence[-2] end fib_sequence end` in ruby
write this so that it lists all the fibonacci terms: `def fibo(n) n if n < 2 a = 1 b = 1 (1..n).each { |_| a, b = b, a + b } a end` in ruby
gistlib
by LogSnag