def fibonacci(n) fibTable = [] if (n == 0) or (n == 1) return 1 else if fibTable.at(n-1) == nil fibTable.insert(n-1, fibonacci(n-1)) fib1 = fibTable.at(n-1) else fib1 = fibTable.at(n-1) end if fibTable.at(n-2) == nil fibTable.insert(n-2, fibonacci(n-2)) fib2 = fibTable.at(n-2) else fib2 = fibTable.at(n-2) end return fib1 + fib2 end end sum = 0 for i in 1..32 fib = fibonacci(i) if (fib%2) == 0 sum += fib end end puts sum