Ad
  • Custom User Avatar

    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!

  • Custom User Avatar

    Using Stream, this is the best practice I think. Since there is a special method "findFirst()" in Stream class!

  • Custom User Avatar

    Replacing "jokers" in one forward loop! It reminds me the "Eratosthenes Sieve" algorithm! Clever and fast way!