implementation of 24game/solve (squashed)