File tree 1 file changed +10
-8
lines changed
1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 1
1
from enum import Enum , auto
2
+ from collections import namedtuple
3
+ from numbers import Number
2
4
3
5
4
- Coordinate = tuple [ int , int ]
6
+ Coordinate : tuple [ Number , Number ] = namedtuple ( "Coordinate" , [ "x" , "y" ])
5
7
6
8
7
9
def add (a : Coordinate , b : Coordinate ) -> Coordinate :
8
- xa , ya = a
9
- xb , yb = b
10
- return xa + xb , ya + yb
10
+ return Coordinate (a .x + b .x , a .y + b .y )
11
11
12
12
13
13
def sub (a : Coordinate , b : Coordinate ) -> Coordinate :
14
- xa , ya = a
15
- xb , yb = b
16
- return xa - xb , ya - yb
14
+ return Coordinate (a .x - b .x , a .y - b .y )
17
15
18
16
19
- def manhattan_dist (a : Coordinate , b : Coordinate ) -> Coordinate :
17
+ def mult (a : Coordinate , b : Number ) -> Coordinate :
18
+ return Coordinate (a .x * b , a .y * b )
19
+
20
+
21
+ def manhattan_dist (a : Coordinate , b : Coordinate ) -> Number :
20
22
x , y = sub (b , a )
21
23
return abs (x ) + abs (y )
22
24
You can’t perform that action at this time.
0 commit comments