solved part 1 day8 2024
This commit is contained in:
1 parent
520aa782da
commit
e5f3e9015f
4 files changed
+141
No files matched your search
@@ -0,0 +1,31 @@
|
||||
from typing import Self
|
||||
|
||||
import math
|
||||
|
||||
class Vector:
|
||||
x: int
|
||||
y: int
|
||||
|
||||
def __init__(self, x: int, y: int):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def __add__(self, other: Self) -> Self:
|
||||
return Vector(self.x + other.x, self.y + other.y)
|
||||
|
||||
def __sub__(self, other: Self) -> Self:
|
||||
return Vector(self.x - other.x, self.y - other.y)
|
||||
|
||||
def abs(self) -> Self:
|
||||
return Vector(abs(self.x), abs(self.y))
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'{self.x}, {self.y}'
|
||||
|
||||
def __eq__(self, value: Self) -> bool:
|
||||
return self.x == value.x and self.y == value.y
|
||||
|
||||
def distance(self, other: Self) -> int:
|
||||
return math.sqrt((other.x - self.x)**2 + (other.y - self.y)**2)
|
||||
|
||||
|
||||
Reference in new issue
Block a user