I think Groovy test environment is broken. In GUI mode it sometimes fails with the message:
Timeout: your program did not provide an input in due time.
When I run that test again everything is ok.
When I submit my solution some tests are broken. The same code passes all GUI tests, but then 50% fails. I submit my code again and then 25% fails. And I submit is again and then 20% fails.
I think code is good. Similar code works in Python, Java, JavaScript, C++ and other languages, so I think something is wrong with Groovy test environment.