+ 9

Why does this code get a timeout?

nothing but a few prints https://code.sololearn.com/cInx9q7ZVqqz/?ref=app

18th Sep 2018, 6:57 AM
Oma Falk
Oma Falk - avatar
9 Respostas
+ 6
Oma Falk , somehow Sololearn takes too long to print things. If you skip the printing it works fine. But I suppose that's the whole purpose of the code. Maybe print just parts of it?
18th Sep 2018, 9:07 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 6
yes the bottleneck is the print. I will live the art of limited ressources.
18th Sep 2018, 10:43 AM
Oma Falk
Oma Falk - avatar
+ 5
I tried it on online compiler and it worked so I think it's sololearn's wine
18th Sep 2018, 7:07 AM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 5
it works now, and then fails another time
18th Sep 2018, 3:25 PM
Mark đŸ‡ș🇬 [INACTIVE]
Mark đŸ‡ș🇬 [INACTIVE] - avatar
+ 4
Might be a combination of the time that each print() needs and the fact that lists are rather slow if you use them as queues. I tried to improve both and it seems to work (a little bit) better. It still gets some time outs though 😔 https://code.sololearn.com/cThvIEuAAOAG/?ref=app /Edit: after testing it again for a couple of times, now my code doesn't seem to perform any better or worse than yours. And now it gets time-outs all the time. Let's just agree that there's something wrong with Sololearn (but it's weird that it shows "time limit exceeded" even after drawing the pattern when it obviously executed the whole code up to the last line because otherwise there wouldn't be any output đŸ€”)
18th Sep 2018, 12:51 PM
Anna
Anna - avatar
+ 4
change both ranges to 6 or 7 and then run the code ~ your design appears Oma Falk
18th Sep 2018, 1:21 PM
BroFar
BroFar - avatar
+ 3
Use codiva.io website to code. I would advice using Google Chrome.
18th Sep 2018, 10:05 AM
Sahil Devgun
Sahil Devgun - avatar
+ 3
My original template switches stdout to a buffered writer; this replacement has better control: import sys, io sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding="utf16", newline="\n") # Params: line_buffering=False, write_through=True, errors="ignore", ... # newline=... disables magic replaces + increases output len # sys.stdout.flush() # maybe useful? Noting that utf16 uses wider chars (BOM = byte order mark): print(len('\u25a0'.encode('utf16'))) # 4 print(bytes('\u25a0', 'utf16')) # fffea025 : BOM + unicode Modifying Anna's code this way always finishes (fast): print(s[:2047], end="") This way always lags + Time Limit Exceeded: print(s[:2048], end="") (s[:1972] and s[:1973] if newline= is omitted above. I don't know if ASCII-only has different limits) == Conclusion == I'll tell SoloLearn, but it may not be a bug. For now, probably keep utf16 output below 2KB. If you try the new header in your codes: * Modules may try to use sys.__stdout__ * If they do: you may get unexpected Chinese glyphs * : Reassign sys.__stdout__ the same way.
18th Sep 2018, 11:20 PM
Kirk Schafer
Kirk Schafer - avatar
+ 3
New info: Output lag and Compiler Error here, added to theoretical bug report: https://www.sololearn.com/Discuss/1518887/?ref=app
25th Sep 2018, 5:02 AM
Kirk Schafer
Kirk Schafer - avatar