def codes(edge):
    """Return forward and backward codes for the given tile edge, a list
    of the characters ("0" or "1") on an edge of the matrix.
    """
    fwd = int("".join(edge), 2)
    back = int("".join(reversed(edge)), 2)
    return fwd, back