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.
Interesting thought, but the kata states it's only a draw if nobody can make another move.
Can someone please explain how the list variable r get changed on the fix function?
I thought the l is a local variable, how does it affect the r variable on the original function?
OK, i kept digging.. it turned out that list are mutalbe which means that l and r refer to the same address and changing one of them will change also the other one.
I think the problem is not so much the test cases but the order in which the set() arranges all the letters. Because there are times in which only 1 iteration through the triplets won't be enough to rearrange properly the letters in r. This is because of the nature of the random sorting of the set() module. If it runs twice as azzbcc says it works, but maybe it's overdoing it.
having said that, it's a wonderful solution...
This is an example of a failing test case:
triplets = [['t', 'u', 'p'], ['w', 'h', 'i'], ['t', 's', 'u'], ['a', 't', 's'], ['h', 'a', 'p'], ['t', 'i', 's']]
I think so. The 'for l in triplets' loop should run twice.
I would also be interesting in seeing a test in which this solution fails.
Can you provide a test case?
I will test it
btw: func
fix
not a swapthx
The front part's short and sweet.
However, the last line is wrong. Just because the board contains at least one unfilled square doesn't mean it's not solved yet.
For instance,
1 1 2
2 2 1
1 2 0
is a draw, but this code returns -1
This solution is incomplete though elegant, it will fail for some test cases currently not included.
The 'for l in triplets' loop shouldn't run just once, it should run until there are no more swaps.