2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00

Adjust Python code to follow PEP8

This commit is contained in:
Martin Thoma 2015-11-20 23:12:22 +01:00
parent b36776fc27
commit de1ad26035
14 changed files with 349 additions and 311 deletions

View file

@ -1,12 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def get_next(n, i, damen_pos):
for i in range(n):
candidates = set(list(range(n)))
candidates = set(list(range(n)))
candidates -= set(damen_pos)
candidates -= set(list(range(damen_pos[i]+1)))
candidates = list(candidates)
candidates = list(candidates)
if len(candidates) > 0:
damen_pos[i] = candidates[0]
return i, damen_pos
@ -14,6 +15,7 @@ def get_next(n, i, damen_pos):
damen_pos = damen_pos[0:i] + [0]*(n-i)
i -= 1
def is_attacked(damen, x, y):
""" Wird das Feld (x,y) von einer der Damen angegriffen? """
for dy, dx in enumerate(damen[:y]):
@ -21,9 +23,10 @@ def is_attacked(damen, x, y):
return True
return False
def finde_loesung(n):
""" Platziere n Damen so auf einem n×n Feld,
sodass sich keine Damen schlagen.
sodass sich keine Damen schlagen.
"""
# damen[i] ist die x-position von Dame i in Zeile i
damen = [0]*n
@ -37,8 +40,9 @@ def finde_loesung(n):
i += 1
i, damen = get_next(n, i, damen)
def alle_loesungen(n):
generator = finde_loesung(n)
return list(generator)
print(len(alle_loesungen(11)))
print(len(alle_loesungen(11)))