Любомир обнови решението на 14.10.2014 20:18 (преди около 10 години)
+def fibonacci(number)
+ if number == 1 or number == 2
+ 1
+ else
+ fibonacci(number - 1) + fibonacci(number - 2)
+ end
+end
+
+def lucas(number)
+ if number == 1
+ 2
+ elsif number == 2
+ 1
+ else
+ lucas(number - 1) + lucas(number - 2)
+ end
+end
+
+def series(sequence, number)
+ case sequence
+ when 'fibonacci' then fibonacci(number)
+ when 'lucas' then lucas(number)
+ when 'summed' then fibonacci(number) + lucas(number)
+ else "Unknown sequence."
+ end
+end