Remove debug
This commit is contained in:
parent
24b7437128
commit
e5c56950ef
|
@ -7,7 +7,6 @@ from time import sleep
|
|||
# PADDING = int(os.popen('tput cols').read()) // 3 # '// 2 - 6' for exact middle for n=4
|
||||
PADDING = 5
|
||||
DEBUG = False
|
||||
# ITER = -1
|
||||
|
||||
def get_board_dim(board: list) -> int:
|
||||
return int(len(board) ** 0.5)
|
||||
|
@ -62,8 +61,6 @@ def get_constraints(board: list, border: list, pos: int) -> list:
|
|||
return constraints
|
||||
|
||||
def check_constraint(slice: list, constraint: int) -> bool:
|
||||
global ITER
|
||||
|
||||
constraint = int(constraint)
|
||||
peak = 0
|
||||
visible_towers = 0
|
||||
|
@ -72,12 +69,10 @@ def check_constraint(slice: list, constraint: int) -> bool:
|
|||
return True
|
||||
|
||||
board_dim = len(slice)
|
||||
# print()
|
||||
for i, tower in enumerate(slice):
|
||||
if tower > peak:
|
||||
peak = tower
|
||||
visible_towers += 1
|
||||
# print(f'{i=} {tower=} {peak=} {visible_towers=} {constraint=} {ITER=}')
|
||||
if visible_towers > constraint:
|
||||
return False
|
||||
if constraint + tower > board_dim + 1 + i:
|
||||
|
@ -88,16 +83,9 @@ def check_constraint(slice: list, constraint: int) -> bool:
|
|||
return True
|
||||
|
||||
def is_valid_state(board: list, border: list, next_candidate_index: int) -> bool:
|
||||
# global ITER
|
||||
|
||||
row = get_row(board, next_candidate_index)
|
||||
column = get_col(board, next_candidate_index)
|
||||
constraints = get_constraints(board, border, next_candidate_index)
|
||||
# ITER += 1
|
||||
# if ITER % 100000 == 0:
|
||||
# os.system('clear')
|
||||
# print_board(board, border)
|
||||
# print(f'{ITER=}')
|
||||
satisfies_constraints = all([
|
||||
check_constraint(column, constraints[0]),
|
||||
check_constraint(row, constraints[2]),
|
||||
|
@ -132,7 +120,6 @@ def backtrack_skyscrapers(board: list, sols: list, border: list) -> None:
|
|||
for candidate in candidates:
|
||||
board[next_candidate_index] = candidate
|
||||
if DEBUG:
|
||||
# sleep(2)
|
||||
input()
|
||||
os.system('clear')
|
||||
print_board(board, border)
|
||||
|
@ -172,10 +159,9 @@ if __name__ == '__main__':
|
|||
# main('2 1 1 2 2 1 1 2') # 2 x 2
|
||||
# main('3 2 1 1 2 2 3 2 1 1 2 2') # 3 x 3
|
||||
# main('4 3 2 1 1 2 2 2 4 3 2 1 1 2 2 2') # original problem
|
||||
# main('') # original problem
|
||||
# main('3 2 2 1 1 2 1 1 4 2 1 2 1 2 2 2') # henri's problem
|
||||
# main('2 1 2 3 3 2 3 1 3 2 2 1 3 3 2 3 4 2 1 2') # 5 x 5
|
||||
# main('1 2 2 4 3 5 4 4 2 2 2 1 1 2 3 4 2 4 5 3 3 2 2 1') # 6 x 6
|
||||
main('6 3 1 3 3 3 2 1 2 3 3 3 3 3 3 7 3 4 3 2 1 2 1 2 2 3 3 4') # 7 x 7
|
||||
# main('6 3 1 3 3 3 2 1 2 3 3 3 3 3 3 7 3 4 3 2 1 2 1 2 2 3 3 4') # 7 x 7
|
||||
# main('7 4 2 3 3 2 1 1 2 2 2 3 4 6 6 5 4 2 3 2 1 1 2 2 4 2 4 4') # 7 x 7
|
||||
# main('4 3 4 1 5 4 3 2 2 4 2 4 1 3 5 4 3 3 5 2 3 1 3 2 2 1 2 3 2 4 3 3') # 8 x 8
|
||||
main('4 3 4 1 5 4 3 2 2 4 2 4 1 3 5 4 3 3 5 2 3 1 3 2 2 1 2 3 2 4 3 3') # 8 x 8
|
||||
|
|
Loading…
Reference in New Issue