summaryrefslogtreecommitdiffstats
path: root/solutions/py/03-1.py
blob: dea1c058f244e5e5d9b12bb578a4393bdf0d33a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import math


def intersection(l1, l2):
    tmp = set(l1)
    return [value for value in l2 if value in tmp]

def man_dist(point):
    return abs(point[0]) + abs(point[1])


wire1 = []
wire2 = []
for wire in (wire1, wire2):
    x = 0
    y = 0
    dx = 0
    dy = 0
    for move in input().split(","):
        if move[0] == "D":
            dx = 0
            dy = -1
        elif move[0] == "U":
            dx = 0
            dy = 1
        elif move[0] == "R":
            dx = 1
            dy = 0
        elif move[0] == "L":
            dx = -1
            dy = 0
        for i in range(int(move[1:])):
            x += dx
            y += dy
            wire.append((x, y))
points = intersection(wire1, wire2)
print(len(points))
dist = man_dist(points[0])
for point in points[1:]:
    dist = min(dist, man_dist(point))
print(dist)