-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
37 lines (28 loc) · 842 Bytes
/
helper.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
from dataclasses import dataclass
@dataclass(frozen=True)
class Point():
x : int
y : int
def double(self):
return Point(2*self.x,self.y)
def right(self):
return Point(self.x+1,self.y)
def left(self):
return Point(self.x-1,self.y)
def up(self):
return Point(self.x,self.y-1)
def down(self):
return Point(self.x,self.y+1)
def l1dist(self,other):
return abs(self.x - other.x) + abs(self.y - other.y)
def move(self,d):
if d == "<":
return self.left()
if d == ">":
return self.right()
if d == "^":
return self.up()
if d == "v":
return self.down()
def within(self,grid):
return self.x >= 0 and self.x < grid[0] and self.y >= 0 and self.y < grid[1]