Бетина обнови решението на 11.10.2014 19:49 (преди около 10 години)
+def series (sequence_name,index)
+ if sequence_name=='fibonacci' then result=fibonacci(index)
+ elsif sequence_name=='lucas' then result=lucas(index)
+ else result=summed(index)
+ end
+ return result
+end
+
+def fibonacci(index)
+ if index==1 or index==2 then result=1
+ else result=fibonacci(index-1)+fibonacci(index-2)
+ end
+ return result
+end
+
+def lucas(index)
+ if index==1 then result=2
+ elsif index==2 then result=1
+ else result=lucas(index-1)+lucas(index-2)
+ end
+ return result
+end
+
+def summed(index)
+ result=fibonacci(index)+lucas(index)
+ return result
+end