an exercise in recursive backtracking