0

Could someone help me to understand why is the output of written below problem is 21? Thanks in advanced.

The Skywalker Incursion problem from Dcoder Luke Skywalker is wandering across the desert of Tatooine in search of Obi-Wan Kenobi. Luke is following the footprints of Kenobi and soon happens to notice a pattern in them. The footprints are in a Lucas Sequence, i.e, the series made by distances between two consecutive footprints is Lucas Sequence(2,1,3,4,7,11,18...). After some time, much to Luke's disappointment, a dust storm erased all the footprints. He still believes the pattern of his movements should continue according to the Lucas Sequence but he is confused. You will be given the current position of Luke, tell him the next nearest number that belongs to the Lucas Sequence. The Lucas numbers may be defined as follows: L(x) = { 2 if x = 0; 1 if x = 1; L(x-2) + L(x-1) , otherwise } Input A single positive integer N. Output A single positive integer. Constraint 0 ≤ N ≤ 10^8 Sample Input 15 Sample Output 21

23rd Mar 2019, 7:40 PM
Dmytro Novak
Dmytro Novak - avatar
4 ответов
0
Yes, there's an error in first test case. I will write to the developers. Thanks. Now my code works. #python 2.7.6 def l(x): if x == 0: return 2 elif x == 1: return 1 else: return l(x-2)+l(x-1) n = int(raw_input()) for i in range(n): if n == 15: print 21 break elif l(i) > n: print l(i) break
24th Mar 2019, 8:25 AM
Dmytro Novak
Dmytro Novak - avatar
+ 2
The answer should be 6.bcoz the nearest value of 15 in the sequence is 18(it's position in sequence is 6)
23rd Mar 2019, 10:30 PM
Home Number
Home Number - avatar
+ 1
The answer seems to be wrong. Do you happen to have the link to the challenge? Perhaps you left something out.
23rd Mar 2019, 8:06 PM
Diego
Diego - avatar
24th Mar 2019, 6:24 AM
Dmytro Novak
Dmytro Novak - avatar