78 lines
1.3 KiB
Python
78 lines
1.3 KiB
Python
import sys
|
|
import os
|
|
from pprint import pprint
|
|
import time
|
|
|
|
|
|
from shapely.geometry import Point
|
|
from shapely.geometry.polygon import Polygon
|
|
import shapely
|
|
|
|
import numpy as np
|
|
|
|
from matplotlib.path import Path
|
|
import sympy
|
|
#colors
|
|
from termcolor import colored
|
|
|
|
def p(x,inside):
|
|
for idx,i in enumerate(x):
|
|
for jdx,j in enumerate(i):
|
|
|
|
#if j == '#':
|
|
# print(colored(j,'red'),end='')
|
|
#if (idx,jdx) in steps:
|
|
# print(colored(j,'blue'),end='')
|
|
if (idx,jdx) in inside:
|
|
print(colored(j,'green'),end='')
|
|
else:
|
|
print(j,end='')
|
|
print()
|
|
|
|
input_f = ''
|
|
if len(sys.argv) == 1:
|
|
input_f = 'test'
|
|
else:
|
|
input_f = sys.argv[1]
|
|
|
|
grid = []
|
|
|
|
with open(input_f) as file:
|
|
for line in file:
|
|
grid.append(line.rstrip().split())
|
|
|
|
steps = []
|
|
|
|
size = 20
|
|
|
|
cur = (0,0)
|
|
|
|
#cur = (int(size/2),int(size/2))
|
|
|
|
steps.append(cur)
|
|
|
|
for i in grid:
|
|
direction,length,color = i
|
|
length = int(length)
|
|
|
|
if direction == 'R':
|
|
cur = (cur[0],cur[1]+length)
|
|
|
|
if direction == 'D':
|
|
cur = (cur[0]+length,cur[1])
|
|
|
|
if direction == 'L':
|
|
cur = (cur[0],cur[1]-length)
|
|
|
|
if direction == 'U':
|
|
cur = (cur[0]-length,cur[1])
|
|
|
|
steps.append(cur)
|
|
|
|
polygon = Polygon(steps)
|
|
|
|
area = polygon.buffer(0.5,join_style="mitre").area
|
|
|
|
print(int(area))
|
|
|