Do day 18.
This commit is contained in:
11
lib.py
11
lib.py
@@ -31,6 +31,8 @@ class Grid2D:
|
||||
NE = (-1, 1)
|
||||
SE = (1, 1)
|
||||
SW = (1, -1)
|
||||
COORDS_ORTH = (N, E, S, W)
|
||||
COORDS_DIAG = (NW, NE, SE, SW)
|
||||
|
||||
def __init__(self, text: str):
|
||||
lines = [line for line in text.splitlines() if line.strip() != ""]
|
||||
@@ -222,3 +224,12 @@ class A_Star(object):
|
||||
g_score[neighbor] = tentative_g_score
|
||||
f_score = g_score[neighbor] + h(neighbor)
|
||||
heapq.heappush(open_set, (f_score, neighbor))
|
||||
|
||||
def shoelace_area(corners):
|
||||
n = len(corners)
|
||||
area = 0
|
||||
for i in range(n):
|
||||
x1, y1 = corners[i]
|
||||
x2, y2 = corners[(i + 1) % n]
|
||||
area += (x1 * y2) - (x2 * y1)
|
||||
return abs(area) / 2.0
|
||||
|
||||
Reference in New Issue
Block a user