def compose_paths(path_0, path_1):
    """
    The binary representation of a path is a 1 (which means "stop"), followed by the
    path as binary digits, where 0 is "left" and 1 is "right".

    Look at the diagram at the top for these examples.

    Example: 9 = 0b1001, so right, left, left
    Example: 10 = 0b1010, so left, right, left

    How it works: we write both numbers as binary. We ignore the terminal in path_0, since it's
    not the terminating condition anymore. We shift path_1 enough places to OR in the rest of path_0.

    Example: path_0 = 9 = 0b1001, path_1 = 10 = 0b1010.
    Shift path_1 three places (so there is room for 0b001) to 0b1010000.
    Then OR in 0b001 to yield 0b1010001 = 81, which is right, left, left, left, right, left.
    """
    mask = 1
    temp_path = path_0
    while temp_path > 1:
        path_1 <<= 1
        mask <<= 1
        temp_path >>= 1
    mask -= 1
    path = path_1 | path_0 & mask
    return path
