mirror of
https://github.com/Xevion/advent-of-code.git
synced 2025-12-06 01:14:18 -06:00
day 6 part 1 inital try
This commit is contained in:
50
2018/day-6/input
Normal file
50
2018/day-6/input
Normal file
@@ -0,0 +1,50 @@
|
||||
342, 203
|
||||
79, 64
|
||||
268, 323
|
||||
239, 131
|
||||
246, 87
|
||||
161, 93
|
||||
306, 146
|
||||
43, 146
|
||||
57, 112
|
||||
241, 277
|
||||
304, 303
|
||||
143, 235
|
||||
253, 318
|
||||
97, 103
|
||||
200, 250
|
||||
67, 207
|
||||
345, 149
|
||||
133, 222
|
||||
232, 123
|
||||
156, 359
|
||||
80, 224
|
||||
51, 145
|
||||
138, 312
|
||||
339, 294
|
||||
297, 256
|
||||
163, 311
|
||||
241, 321
|
||||
126, 66
|
||||
145, 171
|
||||
359, 184
|
||||
241, 58
|
||||
108, 312
|
||||
117, 118
|
||||
101, 180
|
||||
58, 290
|
||||
324, 42
|
||||
141, 190
|
||||
270, 149
|
||||
209, 294
|
||||
296, 345
|
||||
68, 266
|
||||
233, 281
|
||||
305, 183
|
||||
245, 230
|
||||
161, 295
|
||||
335, 352
|
||||
93, 66
|
||||
227, 59
|
||||
264, 249
|
||||
116, 173
|
||||
38
2018/day-6/python/main.py
Normal file
38
2018/day-6/python/main.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import os, sys, collections
|
||||
|
||||
path = os.path.join(sys.path[0], '..', 'input')
|
||||
# data = open(path, 'r').read().split('\n')
|
||||
data = """1, 1
|
||||
1, 6
|
||||
8, 3
|
||||
3, 4
|
||||
5, 5
|
||||
8, 9""".split('\n')
|
||||
points = list(map(lambda item : [int(num.strip()) for num in item.split(', ')], data))
|
||||
|
||||
def manhattan(pos1, pos2):
|
||||
return abs(pos2[0] - pos1[0]) + abs(pos2[1] - pos1[1])
|
||||
|
||||
def closest(pos):
|
||||
return min(points, key=lambda point : manhattan(point, pos))
|
||||
|
||||
|
||||
grid = collections.defaultdict(dict)
|
||||
scores = collections.defaultdict(dict)
|
||||
for pos in points:
|
||||
scores[pos[0]][pos[1]] = 0
|
||||
ensure = 500
|
||||
for x in range(-ensure, ensure):
|
||||
for y in range(-ensure, ensure):
|
||||
pos = closest((x, y))
|
||||
# grid[x][y] = pos
|
||||
scores[pos[0]][pos[1]] += 1
|
||||
|
||||
from pprint import pprint
|
||||
# pprint(scores)
|
||||
true_scores = []
|
||||
for x, yy in scores.items():
|
||||
for y, score in yy.items():
|
||||
true_scores.append(("({}, {}) : {}".format(x, y, score), score))
|
||||
true_scores.sort(key=lambda item : item[1])
|
||||
pprint([score[0] for score in true_scores])
|
||||
Reference in New Issue
Block a user