trials: recursive backtracking implemented