n-queens: use list comprehension instead of for loop
This commit is contained in:
parent
a4249017c0
commit
7ee2c4ad8f
1 changed files with 2 additions and 5 deletions
|
@ -32,11 +32,8 @@ def solve(n):
|
|||
positions[row]-k != positions[row+k]
|
||||
for row in range(0, n-1) for k in range(1, n-row)))
|
||||
|
||||
solutions = []
|
||||
for positions in permutations(range(1, n+1)):
|
||||
if valid(positions):
|
||||
solutions.append(positions)
|
||||
return solutions
|
||||
return [positions for positions in permutations(range(1, n+1))
|
||||
if valid(positions)]
|
||||
|
||||
|
||||
def fundamental(solutions):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue