-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday5a.py
89 lines (66 loc) · 1.93 KB
/
day5a.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from collections import Counter
f = open("input.txt", "r")
#f = open("testInput.txt", "r")
dat = f.read().splitlines()
seen = {}
numOverTwo = 0
for line in dat:
s,e = line.split(" -> ")
x1,y1 = [int(n) for n in s.split(",")]
x2,y2 = [int(n) for n in e.split(",")]
#print(str(x1)+","+str(y1)+" "+str(x2)+","+str(y2))
if x1 == x2:
while y1 != y2:
if (x1,y1) not in seen:
seen[(x1,y1)] = 1
else:
seen[(x1,y1)] += 1
if y1 < y2:
y1 += 1
else:
y1 -= 1
#print(str(x1)+","+str(y1)+" "+str(x2)+","+str(y2))
if (x1,y1) not in seen:
seen[(x1,y1)] = 1
else:
seen[(x1,y1)] += 1
elif y1 == y2:
while x1 != x2:
if (x1,y1) not in seen:
seen[(x1,y1)] = 1
else:
seen[(x1,y1)] += 1
if x1 < x2:
x1 += 1
else:
x1 -= 1
#print(str(x1)+","+str(y1)+" "+str(x2)+","+str(y2))
if (x1,y1) not in seen:
seen[(x1,y1)] = 1
else:
seen[(x1,y1)] += 1
elif abs(y1 - y2) == abs(x1 - x2):
while x1 != x2 and y1 != y2:
if (x1,y1) not in seen:
seen[(x1,y1)] = 1
else:
seen[(x1,y1)] += 1
if x1 < x2:
x1 += 1
else:
x1 -= 1
if y1 < y2:
y1 += 1
else:
y1 -= 1
#print(str(x1)+","+str(y1)+" "+str(x2)+","+str(y2))
if (x1,y1) not in seen:
seen[(x1,y1)] = 1
else:
seen[(x1,y1)] += 1
#print()
for k in seen.keys():
if seen[k] > 1:
numOverTwo += 1
#print(seen)
print(numOverTwo)