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
|
import numpy as np
f = open("input");
GRIDSIZE = 1000;
cloth = np.full((GRIDSIZE,GRIDSIZE),0, dtype=int);
part1 = np.count_nonzero(cloth);
print(part1);
for i in f:
for l in range(len(i)):
if i[l] == "@":
claim_id = int(i[1:(l)]);
l_at = l+1;
if i[l] == ",":
claim_l = int(i[l_at:(l)]);
l_at = l+1;
if i[l] == ":":
claim_t = int(i[l_at:(l)]);
l_at = l+1;
if i[l] == "x":
claim_w = int(i[l_at:(l)]);
#l_at = l+1;
claim_h = int(i[l+1:]);
for x in range(claim_l, claim_l+claim_w, 1):
for y in range(claim_t, claim_t+claim_h, 1):
cloth[y,x] +=1;
part1 = np.count_nonzero(cloth);
#print(part1);
part1 = 0;
for i in range(GRIDSIZE):
for j in range(GRIDSIZE):
part1 += 1*(cloth[i,j] > 1);
print("part1", part1);
f = open("input");
for i in f:
#print(i);
for l in range(len(i)):
#print(l, i[l]);
if i[l] == "@":
claim_id = int(i[1:(l)]);
l_at = l+1;
if i[l] == ",":
claim_l = int(i[l_at:(l)]);
l_at = l+1;
if i[l] == ":":
claim_t = int(i[l_at:(l)]);
l_at = l+1;
if i[l] == "x":
claim_w = int(i[l_at:(l)]);
#l_at = l+1;
claim_h = int(i[l+1:]);
#checkclaim = "#" + str(claim_id) +" @ "+str(claim_l)+","+str(claim_t)+": "+str(claim_w)+"x"+str(claim_h);
#print("",i, checkclaim);
#print();
is_overlap = False;
for x in range(claim_l, claim_l+claim_w, 1):
for y in range(claim_t, claim_t+claim_h, 1):
if (cloth[y,x] > 1):
is_overlap = True;
if not is_overlap:
part2 = claim_id;
break;
print("part2", part2);
|