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.
Concise and efficient.
Same here. Caching the results doesn't help and I don't intend to implement a BK-tree on my own for a 3 kyu kata.
EDIT: Calculating the distance has been the bottleneck here. Try a more efficient implementation. It should be able to calculate the distance from
abcdefghijklmno
topqrstuvwxyzabcd
very quickly instead of taking ages.I nearly solved this kata in java but when I attempt with my solution I get 6 tests passed and 1 timeout error. It does not even show the test that my code is failing at. My code passes these tests:
testberry
teststrawbery
testaple
testjavascript
testheaven
testcoddwars
Do you guys know how many test there are in java and what's the last one? It's really hard to sort it out not knowing where it's failing.
Damn... Yeah, I did that translation a while ago and didn't know the problem with arrays used with hashcodes yet. I'll take a look at all of this later.
Actually, my testcases all validated except the randomcases. So I actually had to make a distinction method and then it all ran fine.
Looking at your testcase creation for the random ones; I see you use:
Set<int[]> posAtt = new HashSet<int[]>();
This is where it goes wrong. new int[]{1,3} != new int[]{1,3}
arrays use the default hashcode implementation for checking equals.
here are some possible solutions:
use a SortedSet like TreeSet and give a comparator on creation like: Set<int[]> test = new TreeSet<>(Comparator.comparing(Arrays::toString));
use a Set of lists instead of int[], they actually check the elements on equality.
my personal favourite: use a set of Point. Its an incredibly simply int-tuple that does what you expect.
If you don't want to destroy any of the current solutions, the first suggestion would work fine (altough it's very bad!), but just remember for next time to use an actual Object as keys in sets and maps :)
Done. ;)
If by the 'real life game' you mean person vs person I think it's likely someone aims at the same spot by mistake...whether the player looses a turn or gets a second chance is a matter of the agreement but here if the solution doesn't take that into account multiple points will be scored for the same spot, so I thought it would be nice to clarify whether only unique coordinates will be passed.
ok.
Errr on second thoughts, you don't have to handle this because you will never hit several times the same spot in the "real life" game. Accordingly, the provided attack array never give you duplicate coordinates. That's why most of the solution do not take that into account.
java
language?
Hello, it would be nice to clarify in the instructions if the solution should handle multiple attacks on the same spot. My solution clears all spots that were already attacked in order not to count duplicate points if there is another attack with the same coordinates but I tried a solution that doesn't do that and it also passed all the tests.
exactly, strange it got so many 'clever' votes.
This is not a valid solution, it returns true for {'n','n','n','n','n','w','w','w','w','w'}