Ad
  • Custom User Avatar

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

  • Custom User Avatar

    I strongly agree. I had to make 3 different attempts -- each with a different set of assumptions of what the author might ask me to do -- before I was able to complete this Kata.

  • Custom User Avatar

    That's exactly right! Those groups are called "4-connected components" in this kata (and in topological image processing). Now you can try to solve it to consolidate the theory :)

  • Custom User Avatar

    It counts as one, since every point inside the component can be reached from every other point. I know it can be confusing, but every point can be reached from itself, and since the maximal set of points that constitute the connected component is formed by only one point, then all the points can be reached from every other point in the component (strictly speaking).

    It's important to note that the set of points must be maximal, meaning that an image cannot have a connected component that is a subset of another component.

  • Custom User Avatar

    Maybe I misunderstood it @Dr Gabo, but I'm assuming this would count as 1 component, no ?

    +-----+
    |     |
    |  *  |
    |     |
    +-----+
    

    If not, are there any tests for this? Most solutions consider this valid.

  • Custom User Avatar

    You are kind of on the right track, I'll explain it again because some people seem to still have problems undestanding the concept. A single pixel is never 4-connected by itself, but you can calculate whether or not two pixels are 4-connected. We say that the second assertion holds when they are connected vertically or horizontally (but not diagonally).

    In other words:

    • The question "is the pixel with coordinates (i, j) 4-connected?" does not make sense.
    • The question "are the pixels with coordinates (i1, j1) and (i2, j2) 4-connected?" is valid and makes sense.

    Thus, a 4-connected component is a bunch of pixels where you can go from any pixel to any other by only "jumping" between 4-connected pixels.

    I hope you understand now :)

  • Custom User Avatar

    The description does seem a bit confusing, but there's no need for wikipedia. I think the simplest way I could describe it is: a cluster of connected *s form 1 component (in such way, that if you pick any 2 of those *, you could travel from 1 to the other one by following connected *s, whether it's up,down,left or right).

    If it's just a sole pixel not connected to any other, it still counts as a component. Description shows 2 components: the larger one on the left, and one on the right (4 connected pixels). It may seem like there's more of them, but it's just that spacing between rows is bigger and it looks like there's black pixels in-between :/

    Does that make it any clearer? =/

  • Default User Avatar

    Now they are very good.