Йоана обнови решението на 09.10.2014 10:30 (преди около 10 години)
+def initial_values_for(type)
+ case type
+ when 'fibonacci' then { 1 => 1, 2 => 1}
+ when 'lucas' then { 1 => 2, 2 => 1 }
+ end
+end
+
+def compute_series(type, number)
+ initial_values_for(type)[number] ||
+ compute_series(type, number-1) + compute_series(type, number-2)
+end
+
+def series(type, number)
+ case type
+ when 'summed'
+ compute_series('fibonacci', number) + compute_series('lucas', number)
+ else compute_series(type, number)
+ end
+end