|
|
|
@@ -4,6 +4,27 @@ from typing import Union, Iterator
|
|
|
|
|
from random import choices, choice
|
|
|
|
|
from math import prod
|
|
|
|
|
|
|
|
|
|
ansii_red = "\u001b[31;1m"
|
|
|
|
|
ansii_red_bg = "\u001b[41;1m"
|
|
|
|
|
ansii_green = "\u001b[32;1m"
|
|
|
|
|
ansii_green_bg = "\u001b[42;1m"
|
|
|
|
|
ansii_yellow = "\u001b[33;1m"
|
|
|
|
|
ansii_yellow_bg = "\u001b[43;1m"
|
|
|
|
|
ansii_blue = "\u001b[34;1m"
|
|
|
|
|
ansii_blue_bg = "\u001b[44;1m"
|
|
|
|
|
ansii_magenta = "\u001b[35;1m"
|
|
|
|
|
ansii_magenta_bg = "\u001b[45;1m"
|
|
|
|
|
ansii_reset = "\u001b[0m"
|
|
|
|
|
|
|
|
|
|
thermo_colors = [
|
|
|
|
|
[ ansii_red, ansii_red_bg ],
|
|
|
|
|
[ ansii_yellow, ansii_yellow_bg ],
|
|
|
|
|
[ ansii_blue, ansii_blue_bg ],
|
|
|
|
|
[ ansii_magenta, ansii_magenta_bg ]
|
|
|
|
|
]
|
|
|
|
|
checker_colors_even = [ ansii_green_bg, ansii_green_bg ]
|
|
|
|
|
checker_colors_odd = [ ansii_reset ]
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True, repr=False)
|
|
|
|
|
class Cell:
|
|
|
|
|
row: int
|
|
|
|
@@ -28,18 +49,18 @@ class SolvedCell(FilledCell):
|
|
|
|
|
@dataclass(frozen=True, repr=False)
|
|
|
|
|
class EmptyCell(Cell):
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return "."
|
|
|
|
|
parity = ((self.row // 3) + (self.col // 3)) % 2 == 0
|
|
|
|
|
color = checker_colors_odd[0] if parity else checker_colors_even[0]
|
|
|
|
|
return f"{color}.{ansii_reset}"
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True, repr=False)
|
|
|
|
|
class UninitializedCell():
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return "."
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True, repr=False)
|
|
|
|
|
class Thermo:
|
|
|
|
|
class Thermo(Cell):
|
|
|
|
|
value: int
|
|
|
|
|
color: int
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return f"{self.value}"
|
|
|
|
|
parity = ((self.row // 3) + (self.col // 3)) % 2
|
|
|
|
|
color = thermo_colors[self.color][parity]
|
|
|
|
|
return f"{color}{self.value}{ansii_reset}"
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
class Link:
|
|
|
|
@@ -50,7 +71,7 @@ def pp(c: Cell):
|
|
|
|
|
if isinstance(c, GivenCell):
|
|
|
|
|
return f"{c.value!s}"
|
|
|
|
|
if isinstance(c, SolvedCell):
|
|
|
|
|
return f"\u001b[32;1m{str(c.value)}\u001b[0m"
|
|
|
|
|
return f"{ansii_green}{str(c.value)}{ansii_reset}"
|
|
|
|
|
if isinstance(c, EmptyCell):
|
|
|
|
|
return " "
|
|
|
|
|
return "_"
|
|
|
|
@@ -168,11 +189,8 @@ for value in range(8,0, -1):
|
|
|
|
|
extended_paths : list[Path] = [ new_path + path for path in paths[neighbor]]
|
|
|
|
|
all_paths = [new_path] + extended_paths
|
|
|
|
|
paths[cell].extend(all_paths)
|
|
|
|
|
# for path in paths[cell]:
|
|
|
|
|
# print(f"{cell} has path {pP(path)}")
|
|
|
|
|
|
|
|
|
|
all_paths : list[Path] = [ path for cell in all_cells(solution) for path in paths[cell] ]
|
|
|
|
|
print(len(all_paths))
|
|
|
|
|
# all_paths : list[Path] = [ path for cell in all_cells(solution) for path in paths[cell] ]
|
|
|
|
|
|
|
|
|
|
def get_cells(path: Path) -> Iterator[FilledCell]:
|
|
|
|
|
yield path[0].fr
|
|
|
|
@@ -206,12 +224,11 @@ while num_paths > 0:
|
|
|
|
|
for index, cell in enumerate(cells):
|
|
|
|
|
used_cells.add(cell)
|
|
|
|
|
row, col = cell.row, cell.col
|
|
|
|
|
hints[row][col] = Thermo(index)
|
|
|
|
|
hints[row][col] = Thermo(row, col, index, num_paths - 1)
|
|
|
|
|
num_paths -= 1
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#out = [ " ".join(list(map(str, row))) for row in hints ]
|
|
|
|
|
strs = [ " ".join([str(entry) for entry in row]) for row in hints]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("\n".join(strs))
|
|
|
|
|