python version functional

This commit is contained in:
Maxime Vorwerk
2024-10-03 15:34:05 +02:00
commit fde087dec7
5 changed files with 292 additions and 0 deletions

29
cell.py Normal file
View File

@@ -0,0 +1,29 @@
class cell:
row = []
col = []
square = []
candidates = []
is_set = False
n = -1
def __init__(self, n):
self.candidates = [1,2,3,4,5,6,7,8,9]
self.n = n
def set(self, n):
assert n in self.candidates
self.candidates = [n]
self._prune(n)
self.is_set = True
def _prune(self, n):
for c in self.row:
if n in c.candidates:
c.candidates.remove(n)
for c in self.col:
if n in c.candidates:
c.candidates.remove(n)
for c in self.square:
if n in c.candidates:
c.candidates.remove(n)