Selecting a number from an array, only allowing certain numbers to follow

You might also be interested in the tiled model of the Wave Collapse Function – the algorithm is quite complex, but it takes a list of tiles and connections (exactly like you specify above) and then generates a solution – the solving process can also be animated. See the “tiled” section partway down in this discussion: