diff options
Diffstat (limited to '2018/aoc2018-d03.py')
-rw-r--r-- | 2018/aoc2018-d03.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/2018/aoc2018-d03.py b/2018/aoc2018-d03.py new file mode 100644 index 0000000..c304576 --- /dev/null +++ b/2018/aoc2018-d03.py @@ -0,0 +1,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); + |