repl.it
@Apass_Jack/

RectangleFreeCells_cs109000

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
n= 3 # a prime number. 2, 3, 5, 7, 11, 13, etc
n2 = n * n
n21 = n * n + n
size = n21 + 1

def toA(r): return r//n if r < n2 else (r-n2 if r< n21 else 1)

def toB(r): return r%n if r < n2 else (1 if r< n21 else 0)

def toC(r): return 1 if r < n2 else 0

def toABC(r): return (toA(r), toB(r), toC(r))

def meet(r,c): row = toABC(r); col = toABC(c); return 1 if (row[0] * col[0] + row[1] * col[1] + row[2] * col[2]) % n ==0 else 0

print(size, "x", size, "grid")
for i in range(0, size):
  for j in range(0, size):
    print(meet(i,j), end="")
  print()
Fetching token
?