| 1 |
"""Small test script taken from https://wiki.python.org/moin/SimplePrograms""" |
| 2 |
|
| 3 |
import pwd # F401 'os' imported but unused |
| 4 |
import grp # F401 'os' imported but unused |
| 5 |
|
| 6 |
BOARD_SIZE = 8 |
| 7 |
|
| 8 |
### E265 block comment should start with '# ' |
| 9 |
print("Hello from reviewdog!") |
| 10 |
print("Let's play a small queen problem game to test the flake8 github action.") |
| 11 |
print("This game is taken from https://wiki.python.org/moin/SimplePrograms.") |
| 12 |
|
| 13 |
class BailOut(Exception): |
| 14 |
pass |
| 15 |
|
| 16 |
def validate(queens): |
| 17 |
left = right = col = queens[-1] # E501 line too long (80 > 79 characters). Long description text |
| 18 |
for r in reversed(queens[:-1]): |
| 19 |
left, right = left-1, right+1 |
| 20 |
if r in (left, col, right): |
| 21 |
raise BailOut |
| 22 |
|
| 23 |
def add_queen(queens): |
| 24 |
for i in range(BOARD_SIZE): |
| 25 |
test_queens = queens + [i] |
| 26 |
try: |
| 27 |
validate(test_queens) |
| 28 |
if len(test_queens) == BOARD_SIZE: |
| 29 |
return test_queens |
| 30 |
else: |
| 31 |
return add_queen(test_queens) |
| 32 |
except BailOut: |
| 33 |
pass |
| 34 |
raise BailOut |
| 35 |
|
| 36 |
queens = add_queen([]) |
| 37 |
print (queens) |
| 38 |
print ("\n".join(". "*q + "Q " + ". "*(BOARD_SIZE-q-1) for q in queens)) |
| 39 |
|
| 40 |
import dis # E402 module level import not at top of file |