-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcage.py
More file actions
42 lines (36 loc) · 1.25 KB
/
cage.py
File metadata and controls
42 lines (36 loc) · 1.25 KB
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
import typing
from typing import List, Tuple
class Cage:
def __init__(self, data: List[List[int]], top_left: Tuple[int, int], cage_size: int) -> None:
self.data = data
self.top_left = top_left
self.cage_size = cage_size
def display(self) -> None:
print(self.top_left)
for row in self.data:
for val in row:
print(val, end = " ")
print()
print()
def verify(self) -> bool:
seen = set()
for row in self.data:
for val in row:
if val not in seen:
seen.add(val)
else:
return False
return True
def verifyValue(self, value: int) -> bool:
for row in self.data:
for val in row:
if val == value:
return False
return True
def isInCage(self, row_i: int, col_i: int) -> bool:
if self.top_left[0]<=row_i<self.top_left[0]+self.cage_size:
if self.top_left[1]<=col_i<self.top_left[1]+self.cage_size:
return True
return False
def setFromAbsolute(self, row_i: int, col_i: int, val: int) -> None:
self.data[row_i - self.top_left[0]][col_i - self.top_left[1]] = val