-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheckerboard-covering.py
42 lines (31 loc) · 975 Bytes
/
checkerboard-covering.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
THE CHECKERBOARD COVERING
"""
__author__ = "prakashsellathurai"
__copyright__ = "Copyright 2021"
__version__ = "1.0.1"
__email__ = "prakashsellathurai@gmail.com"
def cover(board, lab=1, top=0, left=0, side=None):
if side is None:
side = len(board)
s = side // 2
offsets = (0, -1), (side - 1, 0)
for dy_outer, dy_inner in offsets:
for dx_outer, dx_inner in offsets:
if not board[top + dy_outer][left + dx_outer]:
board[top + s + dy_inner][left + s + dx_inner] = lab
lab += 1
if s > 1:
for dy in [0, s]:
for dx in [0, s]:
lab = cover(board=board, lab=lab, top=top +
dy, left=left + dx, side=s)
return lab
if __name__ == "__main__":
board = [[0] * 8 for i in range(8)]
board[7][7] = -1
cover(board=board)
for row in board:
print((" %2i" * 8) % tuple(row))