Ad
  • Custom User Avatar

    brackets denote choosing between a number of characters in regex. in this case, picking one of "a", "e", "i", "o", "u", "A", "E", "I", "O", or "U".

  • Default User Avatar

    As long as there exist one valid combination, then the grid is valid.

  • Default User Avatar

    Brilliant solution. Definitely an up vote.

  • Custom User Avatar

    Not a suggestion. And your solution is O(n^2).

  • Custom User Avatar

    Except that if you read the kata description:

    There must be single battleship (size of 4 cells), 2 cruisers (size 3), 3 destroyers (size 2) and 4 submarines (size 1). Any additional ships are not allowed, as well as missing ships.

    You'll see there is no ship of size 5 and in the example ReagentX used there is no 4 cells ship. If you can fit all those ships, without overlapping, then the board is valid. Overlap is forbidden too:

    The ship cannot overlap, but can be contact with any other ship.

  • Default User Avatar

    The guy has a point here, how are we supposed to know the difference between an overlap or a if its just laying side by side, for instance:

    0001000
    0001000
    0111110
    0001000
    0001000

    Above You could assume that two (size 5) ships are overlapping or it can be assumed that one(size 5) ship and two(size 2) ships are independent, Because there is no definition of a ship boundary!!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    That's out. What you have done does not guarantee the equality of two words. Try the case where variable word is 'aabc' and one of variable words is 'abbc'.

  • Default User Avatar

    'I assume you mean that this should test whether a board can be valid'

    Yes, that is what you're supposed to do.

  • Custom User Avatar

    you can't possibly know that it is without information not given by the problem

    pffff... just learn to read, then?

    There must be single battleship (size of 4 cells), 2 cruisers (size 3), 3 destroyers (size 2) and 4 submarines (size 1). Any additional ships are not allowed, as well as missing ships.

  • Custom User Avatar

    Please explain to me how the following board is valid:

    [[3, 3, 3, 0, 0, 0, 0, 0, 0, 0],
     [2, 2, 0, 0, 0, 0, 0, 0, 2, 0],
     [2, 2, 0, 0, 3, 3, 3, 0, 2, 0],
     [2, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [2, 0, 0, 0, 0, 0, 0, 0, 1, 0],
     [0, 0, 0, 0, 3, 3, 3, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    

    You can't, becasue it isn't, ans you can't possibly know that it is without information not given by the problem. "Is the board valid" is not a question you can answer because, as I said in my original comment, just becasue there exists a configuration that can be valid that does not imply that the configuration is valid. Since the problem is to determine if a valid solution exists for a given board the task is not "return true if it has a valid disposition of ships" but rather "return true if it can have a valid disposition of ships" which is a different question entirely.

  • Custom User Avatar

    Not sure why youre so hostile.

    depends... seems to me you downvoted me 5 times in a row while I was answering to your question/trouble. Does that feel friendly to you?

    Please explain to me how you know the board I mentioned in my comment is not the following:

    that's exactly what I told you before, you didn't correctly understood the task. Somewhat:

    I assume you mean that this should test whether a board can be valid, but that is not what the instructions say.

    -> yes (seems you edited that part while I was answering before). But all the same, that's exactly what you're asked for: the question is "is the board valid", not "where each one of the ships is placed?".

  • Custom User Avatar

    Not sure why youre so hostile. Please explain to me how you know the board I mentioned in my comment is not the following:

    [[3, 3, 3, 0, 0, 0, 0, 0, 0, 0],
     [2, 2, 0, 0, 0, 0, 0, 0, 2, 0],
     [2, 2, 0, 0, 3, 3, 3, 0, 2, 0],
     [2, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [2, 0, 0, 0, 0, 0, 0, 0, 1, 0],
     [0, 0, 0, 0, 3, 3, 3, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    
  • Loading more items...