From 47ccffaf81fd0f61479ac28551c278d73be20548 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Sat, 9 Apr 2022 11:19:56 +0200 Subject: [PATCH] allow grid to be between 2 and 9 --- main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 503a919..1aa0743 100644 --- a/main.py +++ b/main.py @@ -24,12 +24,12 @@ OP_LAMBDAS = { OP_NONE: lambda x: x[0], } -BOX_H_LABELS = 'ABCDEF' -BOX_V_LABELS = '654321' +BOX_H_LABELS = 'ABCDEFGHI' +BOX_V_LABELS = '123456789' -def translate_box_to_rc(box): - return BOX_V_LABELS.index(box[1]), BOX_H_LABELS.index(box[0]) +def translate_box_to_rc(box, grid_size): + return BOX_V_LABELS.index(box[1]), BOX_H_LABELS[grid_size-1::-1].index(box[0]) def has_line_integrity(line): @@ -47,7 +47,7 @@ def fill_grid(grid, solution): for box_value in solution: box_values.append(box_value) for box, value in box_values: - br, bc = translate_box_to_rc(box) + br, bc = translate_box_to_rc(box, len(grid)) grid[br][bc] = value return grid @@ -145,7 +145,8 @@ class Block(object): class Game(object): - def __init__(self, grid_size, blocks): + def __init__(self, grid_size: int, blocks): + assert 2 <= grid_size <= 9 self.blocks = blocks self.grid_size = grid_size self.verify()