Solve implemented crudely (without cycle detection)
Solve fully working