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.
Hi, my java solution passes succesffuly most of the time! I noticed that, occasionally it fails. I analysed the situation and found that when two cuiser is stick to each other vertically, my code fails!
I correct my code to overcome, but more adjacent cruiser can be added to java test scenarios.
The field that my test failed was(two sticked cruisers cause my code to fail) :
int[][] battleField12 = {
{ 0, 0, 1, 1, 0, 0, 1, 1, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 0, 0, 1, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 1, 0, 1, 1, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 1, 1, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
I really very enjoyed solving it! It reminds me old school days, playing that game on piece of paper!
Using Stream, this is the best practice I think. Since there is a special method "findFirst()" in Stream class!
Replacing "jokers" in one forward loop! It reminds me the "Eratosthenes Sieve" algorithm! Clever and fast way!