another coding evening
This commit is contained in:
BIN
06/.solve02.py.swp
Normal file
BIN
06/.solve02.py.swp
Normal file
Binary file not shown.
50
06/input.txt
Normal file
50
06/input.txt
Normal file
@ -0,0 +1,50 @@
|
||||
353, 177
|
||||
233, 332
|
||||
178, 231
|
||||
351, 221
|
||||
309, 151
|
||||
105, 289
|
||||
91, 236
|
||||
321, 206
|
||||
156, 146
|
||||
94, 82
|
||||
81, 114
|
||||
182, 122
|
||||
81, 153
|
||||
319, 312
|
||||
334, 212
|
||||
275, 93
|
||||
224, 355
|
||||
347, 94
|
||||
209, 65
|
||||
118, 172
|
||||
113, 122
|
||||
182, 320
|
||||
191, 178
|
||||
99, 70
|
||||
260, 184
|
||||
266, 119
|
||||
177, 178
|
||||
313, 209
|
||||
61, 285
|
||||
155, 218
|
||||
354, 198
|
||||
274, 53
|
||||
225, 138
|
||||
228, 342
|
||||
187, 165
|
||||
226, 262
|
||||
143, 150
|
||||
124, 159
|
||||
325, 210
|
||||
163, 176
|
||||
326, 91
|
||||
170, 193
|
||||
84, 265
|
||||
199, 248
|
||||
107, 356
|
||||
45, 340
|
||||
277, 173
|
||||
286, 44
|
||||
242, 150
|
||||
120, 230
|
||||
6
06/input_sample.txt
Normal file
6
06/input_sample.txt
Normal file
@ -0,0 +1,6 @@
|
||||
1, 1
|
||||
1, 6
|
||||
8, 3
|
||||
3, 4
|
||||
5, 5
|
||||
8, 9
|
||||
50
06/solve01.py
Executable file
50
06/solve01.py
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
def read_input():
|
||||
result = []
|
||||
with open('input.txt', 'r') as f:
|
||||
for line in f:
|
||||
result.append([ int(x) for x in line.split(', ')])
|
||||
return result
|
||||
|
||||
MARGIN=1
|
||||
coord = read_input()
|
||||
coord_min = [ min([x[0] for x in coord]), min([x[1] for x in coord]) ]
|
||||
coord_max = [ max([x[0] for x in coord]), max([x[1] for x in coord]) ]
|
||||
|
||||
finite = [True] * len(coord)
|
||||
area_size = [0] * len(coord)
|
||||
|
||||
|
||||
for x in range(coord_min[0]-MARGIN, coord_max[0]+MARGIN+1):
|
||||
for y in range(coord_min[1]-MARGIN, coord_max[1]+MARGIN+1):
|
||||
border_x = False
|
||||
border_y = False
|
||||
if x in (coord_min[0]-MARGIN, coord_max[0]+MARGIN):
|
||||
border_x = True
|
||||
if y in (coord_min[1]-MARGIN, coord_max[1]+MARGIN):
|
||||
border_y = True
|
||||
|
||||
best = (None, None) #loc, distance
|
||||
for loc_i, loc in enumerate(coord):
|
||||
d = abs(x - loc[0]) + abs(y - loc[1])
|
||||
if best[1] is None:
|
||||
best = (loc_i, d)
|
||||
continue
|
||||
if best[1] > d:
|
||||
best = (loc_i, d)
|
||||
continue
|
||||
if best[1] == d:
|
||||
best = (None, d)
|
||||
continue
|
||||
|
||||
if best[0] is None:
|
||||
continue
|
||||
|
||||
if border_x or border_y:
|
||||
finite[best[0]] = False
|
||||
area_size[best[0]] += 1
|
||||
|
||||
|
||||
print(max([v for k,v in enumerate(area_size) if finite[k]]))
|
||||
29
06/solve02.py
Executable file
29
06/solve02.py
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
def read_input():
|
||||
result = []
|
||||
with open('input.txt', 'r') as f:
|
||||
for line in f:
|
||||
result.append([ int(x) for x in line.split(', ')])
|
||||
return result
|
||||
|
||||
MARGIN=10000
|
||||
coord = read_input()
|
||||
coord_min = [ min([x[0] for x in coord]), min([x[1] for x in coord]) ]
|
||||
coord_max = [ max([x[0] for x in coord]), max([x[1] for x in coord]) ]
|
||||
|
||||
area_size = 0
|
||||
for x in range(coord_max[0]-MARGIN-1, coord_min[0]+MARGIN+1):
|
||||
for y in range(coord_max[1]-MARGIN-1, coord_min[1]+MARGIN+1):
|
||||
|
||||
d_total = 0
|
||||
for loc in coord:
|
||||
if d_total >= MARGIN:
|
||||
break
|
||||
d_total = d_total + abs(x - loc[0]) + abs(y - loc[1])
|
||||
else:
|
||||
if d_total < MARGIN:
|
||||
area_size += 1
|
||||
|
||||
print(area_size)
|
||||
Reference in New Issue
Block a user