-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday10.py
More file actions
75 lines (72 loc) · 3.03 KB
/
day10.py
File metadata and controls
75 lines (72 loc) · 3.03 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
field = '''.............#..#.#......##........#..#
.#...##....#........##.#......#......#.
..#.#.#...#...#...##.#...#.............
.....##.................#.....##..#.#.#
......##...#.##......#..#.......#......
......#.....#....#.#..#..##....#.......
...................##.#..#.....#.....#.
#.....#.##.....#...##....#####....#.#..
..#.#..........#..##.......#.#...#....#
...#.#..#...#......#..........###.#....
##..##...#.#.......##....#.#..#...##...
..........#.#....#.#.#......#.....#....
....#.........#..#..##..#.##........#..
........#......###..............#.#....
...##.#...#.#.#......#........#........
......##.#.....#.#.....#..#.....#.#....
..#....#.###..#...##.#..##............#
...##..#...#.##.#.#....#.#.....#...#..#
......#............#.##..#..#....##....
.#.#.......#..#...###...........#.#.##.
........##........#.#...#.#......##....
.#.#........#......#..........#....#...
...............#...#........##..#.#....
.#......#....#.......#..#......#.......
.....#...#.#...#...#..###......#.##....
.#...#..##................##.#.........
..###...#.......#.##.#....#....#....#.#
...#..#.......###.............##.#.....
#..##....###.......##........#..#...#.#
.#......#...#...#.##......#..#.........
#...#.....#......#..##.............#...
...###.........###.###.#.....###.#.#...
#......#......#.#..#....#..#.....##.#..
.##....#.....#...#.##..#.#..##.......#.
..#........#.......##.##....#......#...
##............#....#.#.....#...........
........###.............##...#........#
#.........#.....#..##.#.#.#..#....#....
..............##.#.#.#...........#.....'''.split()
import numpy as np
rows = len(field)
cols = len(field[0])
asteroids = [[i=='#' for i in row] for row in field]
X, Y = np.meshgrid(range(rows),range(cols))
A = np.array(asteroids)
addrs = np.array([(x,y) for x,y in zip(X[A],Y[A])])
numVis = []
for ast in addrs:
numVis += [len(np.unique(np.arctan2( X[A]-ast[0], Y[A]-ast[1] )))]
print (max(numVis))
stnLoc = numVis.index(max(numVis))
stn = addrs[stnLoc]
dist = np.sqrt(np.sum((stn-addrs)**2,axis=1)) # pythagorean distance
dist[stnLoc] = 999
angles = np.arctan2((stn-addrs)[:,1],(stn-addrs)[:,0])
rotate = np.unique(angles).tolist()
start = rotate.index(np.pi/2)
rotate = rotate[start:] + rotate[:start]
oblitCt = 0
while True:
for a in rotate:
if min(dist[angles==a]) < 999:
kill = addrs.tolist().index(
(addrs[angles==a][np.argmin(dist[angles==a])]).tolist())
dist[kill] = 999
oblitCt += 1
if oblitCt == 200:
break
if oblitCt == 200:
break
kill200 = addrs[kill]
print (kill200[0]*100+kill200[1])