Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ll=open("input").read().splitlines()
- def pick(v,l):
- x,y=zip(*v)
- return int(0.5*abs(sum(x[i]*y[i-1]-x[i-1]*y[i] for i in range(len(v))))+0.5*l+1)
- for p1 in [True,False]:
- dir= {"R":(1,0), "L":(-1,0), "U":(0,1), "D":(0,-1), "0":(1,0), "2":(-1,0), "1":(0,1), "3":(0,-1)}
- x,y,l=0,0,0
- v=[(x,y)]
- for line in ll:
- d, n = (line.split()[0],int(line.split()[1])) if p1 else (line.split()[2][-2], int(line.split()[2][2:-2],16))
- x,y=x+dir[d][0]*int(n),y+dir[d][1]*int(n)
- v.append((x,y))
- l+=n
- print(f"Part 1: {pick(v,l)}") if p1 else print(f"Part 2: {pick(v,l)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement