Ad
  • Custom User Avatar

    That's because the tests are bad in almost every language.

  • Default User Avatar

    Thanks for quick respnose.
    Yes, I saw that, but didn't quite understand what is meant. I thought that zeroes are allowed if they don't break other rules.
    My solution in the given example returns true, but passes all tests as well.

  • Custom User Avatar

    The cells of the sudoku board may also contain 0's, which will represent empty cells. Boards containing one or more zeroes are considered to be invalid solutions.

  • Default User Avatar

    Hello, I think it is not working correct.
    In case below it should return true, but your solution returns false. Am I wrong?
    example:
    int[][] board =
    {
    new []{5, 3, 4, 6, 7, 8, 9, 0, 2},
    new []{6, 7, 2, 1, 9, 5, 3, 4, 8},
    new []{1, 9, 8, 3, 4, 2, 5, 6, 7},
    new []{8, 5, 9, 7, 6, 1, 4, 2, 3},
    new []{4, 2, 6, 8, 5, 3, 7, 9, 1},
    new []{7, 1, 3, 9, 2, 4, 8, 5, 6},
    new []{9, 6, 1, 5, 3, 7, 2, 8, 4},
    new []{2, 8, 7, 4, 1, 9, 6, 3, 5},
    new []{3, 4, 5, 2, 8, 6, 1, 7, 9},
    };

  • Default User Avatar

    I think that it is not working correct.

    1. If the number of ships is less than it should be, your code returns true, but should return false. It return true even if there are no ships at all.
    2. Also it returns true when the ships contact by their corners:
      int[,] field = new int[10, 10]
      {{1, 0, 0, 1, 0, 1, 1, 0, 0, 0},
      {1, 0, 1, 0, 0, 0, 0, 0, 1, 0},
      {1, 0, 1, 0, 1, 1, 1, 0, 1, 0},
      {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
      {0, 0, 0, 0, 1, 0, 0, 0, 1, 0},
      {0, 0, 0, 0, 1, 0, 1, 0, 0, 0},
      {0, 0, 0, 0, 1, 0, 0, 0, 1, 0},
      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
  • Default User Avatar

    As piotr-kasprzyk mentions about an error in the first version of this solution, the error has not been fixed here also:

    Another test that should fail:

    int[,] field = new int[10, 10] {{1, 0, 0, 0, 0, 1, 1, 0, 0, 0}, {1, 0, 1, 0, 0, 0, 0, 0, 1, 0}, {1, 0, 1, 0, 1, 1, 1, 0, 1, 0}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

    Testing horizontal ships after vertical leads to an error of treating 2- and 1-square ships ((5,4)-(6,4) and (5,6)) together as one 3-square ship.
    The length variable stops at 2 for the vertical ship, and then we test horizontal ship which is one square away as it was a continuation of the first one.