Day 05 (glamorized)
This commit is contained in:
@@ -1,19 +1,16 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
lines = (x.strip() for x in open("input.txt"))
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
points = defaultdict(int)
|
points = {}
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
[x1, y1, x2, y2] = list(map(int, re.match(r"(\d+),(\d+) -> (\d+),(\d+)", line).groups()))
|
[x1, y1, x2, y2] = list(map(int, re.match(r"(\d+),(\d+) -> (\d+),(\d+)", line).groups()))
|
||||||
if x1 == x2:
|
if x1 == x2:
|
||||||
for y in range(min(y1, y2), max(y1, y2)+1):
|
for y in range(min(y1, y2), max(y1, y2)+1):
|
||||||
key = '{},{}'.format(x1, y)
|
points[(x1, y)] = points.get((x1, y), 0) + 1
|
||||||
points[key] = points[key] + 1
|
|
||||||
elif y1 == y2:
|
elif y1 == y2:
|
||||||
for x in range(min(x1, x2), max(x1, x2)+1):
|
for x in range(min(x1, x2), max(x1, x2)+1):
|
||||||
key = '{},{}'.format(x, y1)
|
points[(x, y1)] = points.get((x, y1), 0) + 1
|
||||||
points[key] = points[key] + 1
|
|
||||||
|
|
||||||
print(sum(1 if val >= 2 else 0 for val in points.values()))
|
print(sum(1 if val >= 2 else 0 for val in points.values()))
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
|
|
||||||
lines = (x.strip() for x in open("input.txt"))
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
points = defaultdict(int)
|
points = {}
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
[x1, y1, x2, y2] = list(map(int, re.match(r"(\d+),(\d+) -> (\d+),(\d+)", line).groups()))
|
[x1, y1, x2, y2] = list(map(int, re.match(r"(\d+),(\d+) -> (\d+),(\d+)", line).groups()))
|
||||||
@@ -12,7 +11,6 @@ for line in lines:
|
|||||||
range(x1, x2+(x1 <= x2)*2-1, (x1 <= x2)*2-1) if x1 != x2 else repeat(x1),
|
range(x1, x2+(x1 <= x2)*2-1, (x1 <= x2)*2-1) if x1 != x2 else repeat(x1),
|
||||||
range(y1, y2+(y1 <= y2)*2-1, (y1 <= y2)*2-1) if y1 != y2 else repeat(y1)
|
range(y1, y2+(y1 <= y2)*2-1, (y1 <= y2)*2-1) if y1 != y2 else repeat(y1)
|
||||||
):
|
):
|
||||||
key = '{},{}'.format(x, y)
|
points[(x, y)] = points.get((x, y), 0) + 1
|
||||||
points[key] = points[key] + 1
|
|
||||||
|
|
||||||
print(sum(val >= 2 for val in points.values()))
|
print(sum(val >= 2 for val in points.values()))
|
||||||
|
|||||||
Reference in New Issue
Block a user