Решение на Първа задача от София Петрова

Обратно към всички решения

Към профила на София Петрова

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 12 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def fibonacci(number)
return number if number <= 1
fibonacci(number - 1) + fibonacci(number - 2)
end
def lucas(number)
return 2 if number == 1
return 1 if number == 2
lucas(number - 1) + lucas(number - 2)
end
def summed(number)
fibonacci(number) + lucas(number)
end
def series(sequence, number)
case sequence
when 'fibonacci' then fibonacci(number)
when 'lucas' then lucas(number)
when 'summed' then summed(number)
end
end

Лог от изпълнението

............

Finished in 0.02535 seconds
12 examples, 0 failures

История (5 версии и 1 коментар)

София обнови решението на 15.10.2014 13:35 (преди около 10 години)

+def fibonacci(number)
+ return number if number <= 1
+ fibonacci(number - 1) + fibonacci(number - 2)
+end
+
+def lucas(number)
+ return 2 if number == 1
+ return 1 if number == 2
+ lucas(number - 1) + lucas(number - 2)
+end
+
+def summed(number)
+ fibonacci(number) + lucas(number)
+end
+
+def series(sequence, number)
+ return fibonacci(number) if sequence == 'fibonacci'
+ return lucas(number) if sequence == 'lucas'
+ return summed(number) if sequence == 'summed'
+end

София обнови решението на 15.10.2014 13:36 (преди около 10 години)

def fibonacci(number)
- return number if number <= 1
+ return number if number <= 1
fibonacci(number - 1) + fibonacci(number - 2)
end
def lucas(number)
return 2 if number == 1
return 1 if number == 2
lucas(number - 1) + lucas(number - 2)
end
def summed(number)
fibonacci(number) + lucas(number)
end
def series(sequence, number)
return fibonacci(number) if sequence == 'fibonacci'
return lucas(number) if sequence == 'lucas'
return summed(number) if sequence == 'summed'
end

София обнови решението на 15.10.2014 16:31 (преди около 10 години)

def fibonacci(number)
return number if number <= 1
fibonacci(number - 1) + fibonacci(number - 2)
end
def lucas(number)
return 2 if number == 1
return 1 if number == 2
lucas(number - 1) + lucas(number - 2)
end
def summed(number)
fibonacci(number) + lucas(number)
end
def series(sequence, number)
- return fibonacci(number) if sequence == 'fibonacci'
- return lucas(number) if sequence == 'lucas'
- return summed(number) if sequence == 'summed'
+ case sequence
+ when 'fibonacci' then return fibonacci(number)
+ when 'lucas' then return lucas(number)
+ when 'summed' then return summed(number)
+ end
end

София обнови решението на 15.10.2014 16:38 (преди около 10 години)

def fibonacci(number)
return number if number <= 1
fibonacci(number - 1) + fibonacci(number - 2)
end
def lucas(number)
return 2 if number == 1
return 1 if number == 2
lucas(number - 1) + lucas(number - 2)
end
def summed(number)
fibonacci(number) + lucas(number)
end
def series(sequence, number)
case sequence
- when 'fibonacci' then return fibonacci(number)
- when 'lucas' then return lucas(number)
- when 'summed' then return summed(number)
+ when 'fibonacci' then fibonacci(number)
+ when 'lucas' then lucas(number)
+ when 'summed' then summed(number)
end
end

София обнови решението на 15.10.2014 16:41 (преди около 10 години)

def fibonacci(number)
return number if number <= 1
fibonacci(number - 1) + fibonacci(number - 2)
end
def lucas(number)
return 2 if number == 1
return 1 if number == 2
lucas(number - 1) + lucas(number - 2)
end
def summed(number)
fibonacci(number) + lucas(number)
end
def series(sequence, number)
case sequence
when 'fibonacci' then fibonacci(number)
- when 'lucas' then lucas(number)
- when 'summed' then summed(number)
+ when 'lucas' then lucas(number)
+ when 'summed' then summed(number)
end
end