I was looking through the beginner problems yesterday and I found an interesting problem, KCHESS. (I wrote a solution here.)
It is solved by going through every single knight, and then checking if a knight can move to any of the 9 squares the king is in/can move to.
But then I found someone had this extremely short solution in python (which I also rewrote in pascal). This solution just checks if the knight is on the same row/col. And it passes the test cases apparently. I found a test case such that the short solutions don’t work, but the first one I did before works:
1
9
0 1
0 4
1 6
2 6
5 6
6 4
5 0
2 0
4 1
3 3
Where the expected output is:
YES
Since all the squares are under check. The short solutions return NO
but the longer ones return YES
. Test cases probably should be fixed for this problem…