Константин обнови решението на 12.10.2014 22:28 (преди около 10 години)
+def series(name, number)
+ unless name == 'summed'
+ name == 'fibonacci' ? get_fibonacci(number) : get_lucas(number)
+ else
+ get_lucas(number) + get_fibonacci(number)
+ end
+end
+
+def get_fibonacci(number)
+ case number
+ when 1..2 then 1
+ when 3..4 then number-1
+ else get_fibonacci(number - 1) + get_fibonacci(number - 2)
+ end
+end
+
+def get_lucas(number)
+ case number
+ when 1..2 then if (number - 1 == 0) then 2 else 1 end
+ when 3..4 then number
+ else get_lucas(number - 1) + get_lucas(number - 2)
+ end
+end