Backtracking Algorithm Python Example Problem