MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / solve

Method solve

tools/python-3.11.9-amd64/Tools/demo/queens.py:28–36  ·  view source on GitHub ↗
(self, x=0)

Source from the content-addressed store, hash-verified

26 self.nfound = 0 # Instrumentation
27
28 def solve(self, x=0): # Recursive solver
29 for y in range(self.n):
30 if self.safe(x, y):
31 self.place(x, y)
32 if x+1 == self.n:
33 self.display()
34 else:
35 self.solve(x+1)
36 self.remove(x, y)
37
38 def safe(self, x, y):
39 return not self.row[y] and not self.up[x-y] and not self.down[x+y]

Callers 1

mainFunction · 0.95

Calls 4

safeMethod · 0.95
placeMethod · 0.95
displayMethod · 0.95
removeMethod · 0.95

Tested by

no test coverage detected