My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update day10.py

+5 -20
+5 -20
2019/day10.py
··· 11 11 return math.atan2(a[1] - b[1], a[0] - b[0]) 12 12 13 13 14 - EPS = 1e-6 15 - 16 14 # Read problem input 17 15 grid = [] 18 16 asteroids = set() ··· 27 25 height = len(grid) 28 26 29 27 # Part 1 30 - detections = {} 31 - 32 - for y in range(height): 33 - for x in range(width): 34 - if not grid[y][x]: 35 - continue 36 - 37 - p = (x, y) 38 - count = 0 39 - seen_angles = set() 40 - 41 - for other in sorted(asteroids, key=lambda a: dist(p, a))[1:]: 42 - if angle(p, other) not in seen_angles: 43 - seen_angles.add(angle(p, other)) 44 - count += 1 45 - 46 - detections[x, y] = count 28 + detections = { 29 + ast: len(set(angle(ast, other) for other in (asteroids - set(ast)))) 30 + for ast in asteroids 31 + } 47 32 48 33 station, num = max(detections.items(), key=lambda x: x[1]) 49 34 print "Number of detections:", num ··· 68 53 69 54 # Rotate the queue to the starting angle 70 55 start = math.pi / 2 71 - while abs(queue[0][0] - start) > EPS: 56 + while abs(queue[0][0] - start) > 1e-6: 72 57 queue.rotate(-1) 73 58 74 59 # Iterate through the circular list, vaporizing the closest asteroid