0

Why does this time out at more than 106 itterations?

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

13th Aug 2020, 12:39 AM
CarliDe
CarliDe - avatar
11 ответов
+ 4
CarliDe There was an assignment here, a while ago, about this. I'm not sure how many repetitions should be allowed for the code to run within "safe" runtime. Code Playground applies runtime limit for codes here, it's just to be safe in case of infinite loops, something common for fresh learners. I guess your best bet would be to try to run the code (with big max set) locally : )
13th Aug 2020, 2:44 AM
Ipang
+ 4
Its playground problem dont worry your code is correct according to your problem. If you will run your program in other ides it will show complete output. Actully for example i want to print hello 1000 times u need for loop when u run your program it will print some lines after that it will show execution timeout but in other u can see complete output . Enter 9998 as a input u will see only two iterations. Or decrease this number max_test_num = 10000 def check_true(test_num, max_test_num = 10000):
14th Aug 2020, 4:43 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Its playground problem dont worry your code is correct according to your problem. If you will run your program in other ides it will show complete output. Actully for example i want to print hello 1000 times u need for loop when u run your program it will print some lines after that it will show execution timeout but in other u can see complete output . Enter 9998 as a input u will see only two iterations. Or decrease this number you entered high value you need to change instead of 10000 wrote 10 or 20 .... but dont enter big number . max_test_num = 10000 def check_true(test_num, max_test_num = 10000):
14th Aug 2020, 4:44 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Your restrictions are somehow suspicious, but there's no timeout for the "expected" values (between 1 and 10). And greater 10 is completely skipped. Just tried, from moderate negative values over zero up to plus ten everything works fine (as coded). No timeout...?
13th Aug 2020, 12:51 AM
Sandra Meyer
Sandra Meyer - avatar
+ 3
Your initial code was limited to a maximum of 10 iterations. The SL runtime limit is high enough to calculate at least 4000 collatz rows for all numbers from 0 to 4000 with total ~299k calc steps within the collatz function. The print function might be a performance killer.
13th Aug 2020, 5:43 AM
Sandra Meyer
Sandra Meyer - avatar
+ 2
CarliDe You didn't return anything from `check_true` function. When the function returns, `None` will be returned by default. What did you expect as output anyways?
13th Aug 2020, 12:57 AM
Ipang
+ 1
Ipang I am getting 106 print outs before the playground returns "execution timed out" I was hoping I could set the max value to something high and keep checking if every sequential number from the start number.
13th Aug 2020, 2:09 AM
CarliDe
CarliDe - avatar
+ 1
@Sandra Meyer Thank you for trying. This problem has to do with very large numbers. I see now my my max set to 10, as it was when ensuring the basic idea worked. I get a time out at 106 itterations. My coding knowledge is still poor. Is there a limit and what is it based on? Could I not check thousands of numbers against a rule?
13th Aug 2020, 2:16 AM
CarliDe
CarliDe - avatar
+ 1
Ipang Thank you. This gives me some idea of what to study. I'm going to play with it. Honestly I have never succeeded in taking any of my code learning to the "next level". But python is so easy I think I can acheive it. Lots to learn
13th Aug 2020, 3:15 AM
CarliDe
CarliDe - avatar
+ 1
No problem CarliDe 👌 Keep it up and happy coding! 👍
13th Aug 2020, 3:17 AM
Ipang
- 1
@"I am pretty tired of the "Seems like your program requires input" box, too.": I use to build it temporary with hard coded values: my_input = 42; # later: input(); red = 100; # int(input()); green = 200; # int(input()); blue = 233; # int(input()); etc.
13th Aug 2020, 12:53 AM
Sandra Meyer
Sandra Meyer - avatar