Константин обнови решението на 09.10.2014 00:06 (преди около 10 години)
+def calculate_sequence(first_element, second_element, index)
+ sequence = [first_element, second_element]
+ for item in (2...index).to_a
+ sequence[item] = sequence[item - 2] + sequence[item - 1]
+ end
+ return sequence[index - 1]
+end
+
+def series(type, index)
+ if ["fibonacci", "lucas"].include? type
+ first_element = type == "lucas" ? 2 : 1
+ return calculate_sequence(first_element, 1, index)
+ end
+ return calculate_sequence(1, 1, index) + calculate_sequence(2, 1, index)
+end