• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Aoc 2019 Day 10 Problem a guest Dec 13th, 2019 180 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def raytrace(location1,location2):
2.     delta_x = location2 - location1
3.     delta_y = location2 - location1
4.
5.     abs_x = abs(delta_x)
6.     abs_y = abs(delta_y)
7.     raytracing_list = []
8.
9.     try:
10.         ratio = delta_x/delta_y
11.     except ZeroDivisionError:
12.         ratio = 0
13.
14.     if abs_x >= abs_y:
15.
16.         for i in range(abs_x + 1):
17.             xval = i
18.             if delta_x < 0:
19.                 xval = -i
20.             if abs_y != 0:
21.                 yval = xval/ratio
22.             else:
23.                 yval = 0
24.             if yval == int(yval):
25.                 raytracing_list.append((xval,int(yval)))
26.
27.     elif abs_y > abs_x:
28.
29.         for i in range(abs_y + 1):
30.             yval = i
31.             if delta_y < 0:
32.                 yval = -i
33.             xval = ratio * yval
34.             if xval == int(xval):
35.                 raytracing_list.append( (int(xval),yval) )
36.     return raytracing_list
37.
39.
40.     file = open('aoc10.txt', 'r')
42.     file.close()
43.
44.     asteroid_list = []
45.     map_size = (len(input) - 1,len(input))
46.
47.     for y in range(len(input)):
48.         for x in range(len(input[y])):
49.             if input[y][x] == '#':
50.                 asteroid_list.append( (x,y) )
51.
52.     return asteroid_list,map_size
53.
54. def check_asteroid(asteroid,asteroids,map_size):
55.
56.     los = []
57.
58.     for target in asteroids:
59.         line = raytrace(asteroid,target)
60.
61.         for location in line:
62.             position = ( asteroid+location,asteroid+location )
63.             if position in asteroids and position != asteroid:
64.                 if position not in los:
65.                     los.append( position )
66.                 break
67.     return los
68.
70. map_size = initial_data[-1]
71. asteroids = initial_data
72. results = []
73.
74. for asteroid in asteroids:
75.
76.     checker = check_asteroid(asteroid,asteroids,map_size)
77.     results.append(len(checker))
78.
79. results.sort()
80. print(results[-1])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?