0
Why does this time out at more than 106 itterations?
11 Answers
+ 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 : )
+ 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):
+ 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):
+ 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...?
+ 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.
+ 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?
+ 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.
+ 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?
+ 1
No problem CarliDe đ
Keep it up and happy coding! đ
- 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.