Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Great kata! I spent a lot of time debugging and in the end figured out that the problem was float precision issues.
I hope the tests are done in a way that two circles are never almost tangent (unless one is included in the other), since to avoid precision issues one needs to allow some room when checking inequalities.
By the way, in order to plot circles for debugging purposes, one can use GeoGebra online, which has very simple scripting features.
Something does not work with Python, as reported by other users. Even just writing "return 'R'" in the function body, it takes 6-12 seconds to pass/fail all the tests; sometimes it even times out. Some administrator should consider removing the Python version entirely.
See the other version; this one has wrong code description
My solution does not work if the king is attacked but hidden behind some other piece (found this issue while refactoring).
Ah whoops I just looked at the first two examples and thought that (x,y) corresponds to grid[x][y], while it's actually grid[y][x]
In the last basic test I get the grid
[[1, 0, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 0, 1, 1, 1]]
and my answer is:
[(1, 2), (1, 3), (2, 2), (2, 3), (3, 1)]
but I get "Incorrect solution for: [[1, 0, 1, 0, 1], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [1, 0, 1, 0, 1]]".
I believe that my answer works. Note that the solution is not unique when the side of the grid is odd (and at least 3).
Also, I don't see why the error message is printing a different grid.
I wrote a solution which works only when solutions are always integers, and it passed all the tests!
(Integer coefficients are not enough to guarantee this, since 2x=1 gives x=0.5)
It seems that, in all the tests, all the solutions are in fact integers (and one can exploit this to work without approximation errors).
The description should mention this; otherwise, I guess different tests should be used.
This comment is hidden because it contains spoiler information about the solution
What does that mean? Do I need to change any setting somewhere?
Bump: in Python it takes around 6 seconds even if one just writes "return None" in the body of the function.
From the comments below, it seems related to Python 3 and this kata.
Nice kata!
EDIT:
I found the answer to my issue in older discussion.
It would be good, in the problem description, to stress the fact that there could be multiple solutions to the initial game map, but only one if one opens the safe cells carefully (unless the expected answer is '?').
INITIAL POST:
I passed the initial tests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