+ 12

Why are we throwing "Time limit exceeded" to number 3 or higher, and on 2 and lower ones?

https://code.sololearn.com/c21ad8X3TRxw/?ref=app

11th Mar 2018, 11:15 PM
Vučko/Вучко/Vuchko
Vučko/Вучко/Vuchko - avatar
3 Réponses
+ 5
It is because your variable "x" will never be equal to 3 and you will never get out of recursion. So this code call factorial function so many times without returning value and all these calls are pushed in the execution stack. After that python stops the program after limit exceeded.
11th Mar 2018, 11:36 PM
Vladi Petrov
Vladi Petrov - avatar
+ 4
Yes, Vladi Petrov is right. Because x will never equal 3, your program will continuously loop, decrementing x by 3 each time, until x = 3, which will never happen. it is an infinite loop
11th Mar 2018, 11:40 PM
J.G.
J.G. - avatar
+ 1
like the others said, it's an infinite loop; you have to add a break in whatever direction its going to stop it from executing
13th Mar 2018, 8:25 PM
jas
jas - avatar