-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.py
More file actions
80 lines (65 loc) · 2.05 KB
/
Copy pathsample.py
File metadata and controls
80 lines (65 loc) · 2.05 KB
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
import re
# Return a list containing every occurrence of "ai":
from collections import defaultdict
from pip._vendor.msgpack.fallback import xrange
with open("/Users/Bharathan/projects/python_practise/advent_of_code/03_sample_input.txt", "r") as file:
input1 = list(filter(None, file.read().splitlines()))
def initialize_twodlist(foo):
twod_list = []
new = []
for i in range(0, 10):
for j in range(0, 10):
new.append(foo)
twod_list.append(new)
new = []
print(twod_list)
print(initialize_twodlist("a"))
name = "1234567"
print(list(map(lambda c: int(c), name)))
claims = map(lambda s: map(int, re.findall(r'-?\d+', s)), input1)
print("claims")
print(claims)
claims = map(lambda s: map(int, re.findall(r'-?\d+', s)), input1)
m = defaultdict(list)
overlaps = {}
for (claim_number, start_x, start_y, width, height) in claims:
overlaps[claim_number] = set()
for i in xrange(start_x, start_x + width):
for j in xrange(start_y, start_y + height):
if m[(i, j)]:
for number in m[(i, j)]:
overlaps[number].add(claim_number)
overlaps[claim_number].add(number)
m[(i, j)].append(claim_number)
print("a", len([k for k in m if len(m[k]) > 1]))
print("b", [k for k in overlaps if len(overlaps[k]) == 0][0])
from collections import defaultdict
# 1373 @ 130,274: 15x26
C = defaultdict(int)
for line in input1:
words = line.split()
x, y = words[2].split(',')
x, y = int(x), int(y[:-1])
w, h = words[3].split('x')
w, h = int(w), int(h)
for dx in range(w):
for dy in range(h):
C[(x + dx, y + dy)] += 1
for line in input1:
words = line.split()
x, y = words[2].split(',')
x, y = int(x), int(y[:-1])
w, h = words[3].split('x')
w, h = int(w), int(h)
ok = True
for dx in range(w):
for dy in range(h):
if C[(x + dx, y + dy)] > 1:
ok = False
if ok:
print(words[0])
ans = 0
for (r, c), v in C.items():
if v >= 2:
ans += 1
print(ans)