You are reading a single comment by @wence and its replies. Click here to read the full conversation.
  • Each edge of a tile is either:-
    a) Unique, in which case it is one of the border edges
    b) Paired with only one other edge (possibly one being reversed)

    As grams says, non-corner edges only have one unique edge (even considering flipping). Corner edges have two adjacent unique edges (even considering flipping).

    There's no need for any searching at all.

    I processed all tiles and built up a hash/dictionary of edge "numbers" (treating the edge as binary) to tile number. (I took care of the possibility of 'flipped' tiles by also storing the "numbers" associated with the reverse of each of the edges).

    So each tile has 8 "numbers" that map to it.

    You start by finding a corner (because it has two adjacent unique edges). Rotate it so that the two unique edges point outwards (I started top left so the top and left edges needed to be unique). And then the finding an adjacent tile is simply a case of looking up the corresponding edge number in the hash/dictionary (and ignoring the tile number you already have in place) to get the corresponding tile number. Obviously you may need to flip/rotate the tile you find to get it to fit. Lather, rinse, repeat.

  • b) Paired with only one other edge (possibly one being reversed)

    I guess I didn't check the input for these constraints.

  • They do seem to reliably keep the input simple on all of the problems so that solutions can be relatively narrow.

    Also you only needed to know the corners to answer part 1, which is usually a big hint that there's a shortcut to get there.

About

Avatar for wence @wence started