Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7e8c5f4

Browse files
committed
Added day 2018-10
1 parent153aa77 commit7e8c5f4

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

‎2018/10-The Stars Align.py‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# -------------------------------- Input data -------------------------------- #
2+
importos,parse,pathfinding
3+
4+
test_data= {}
5+
6+
test=1
7+
test_data[test]= {"input":"""position=< 9, 1> velocity=< 0, 2>
8+
position=< 7, 0> velocity=<-1, 0>
9+
position=< 3, -2> velocity=<-1, 1>
10+
position=< 6, 10> velocity=<-2, -1>
11+
position=< 2, -4> velocity=< 2, 2>
12+
position=<-6, 10> velocity=< 2, -2>
13+
position=< 1, 8> velocity=< 1, -1>
14+
position=< 1, 7> velocity=< 1, 0>
15+
position=<-3, 11> velocity=< 1, -2>
16+
position=< 7, 6> velocity=<-1, -1>
17+
position=<-2, 3> velocity=< 1, 0>
18+
position=<-4, 3> velocity=< 2, 0>
19+
position=<10, -3> velocity=<-1, 1>
20+
position=< 5, 11> velocity=< 1, -2>
21+
position=< 4, 7> velocity=< 0, -1>
22+
position=< 8, -2> velocity=< 0, 1>
23+
position=<15, 0> velocity=<-2, 0>
24+
position=< 1, 6> velocity=< 1, 0>
25+
position=< 8, 9> velocity=< 0, -1>
26+
position=< 3, 3> velocity=<-1, 1>
27+
position=< 0, 5> velocity=< 0, -1>
28+
position=<-2, 2> velocity=< 2, 0>
29+
position=< 5, -2> velocity=< 1, 2>
30+
position=< 1, 4> velocity=< 2, 1>
31+
position=<-2, 7> velocity=< 2, -2>
32+
position=< 3, 6> velocity=<-1, -1>
33+
position=< 5, 0> velocity=< 1, 0>
34+
position=<-6, 0> velocity=< 2, 0>
35+
position=< 5, 9> velocity=< 1, -2>
36+
position=<14, 7> velocity=<-2, 0>
37+
position=<-3, 6> velocity=< 2, -1>""",
38+
"expected": ['Unknown','Unknown'],
39+
}
40+
41+
test='real'
42+
input_file=os.path.join(os.path.dirname(__file__),'Inputs',os.path.basename(__file__).replace('.py','.txt'))
43+
test_data[test]= {"input":open(input_file,"r+").read().strip(),
44+
"expected": ['RLEZNRAN','10240'],
45+
}
46+
47+
# -------------------------------- Control program execution -------------------------------- #
48+
49+
case_to_test='real'
50+
part_to_test=1
51+
52+
# -------------------------------- Initialize some variables -------------------------------- #
53+
54+
puzzle_input=test_data[case_to_test]['input']
55+
puzzle_expected_result=test_data[case_to_test]['expected'][part_to_test-1]
56+
puzzle_actual_result='Unknown'
57+
58+
59+
# -------------------------------- Actual code execution -------------------------------- #
60+
stars= []
61+
forstringinpuzzle_input.split('\n'):
62+
ifstring=='':
63+
continue
64+
r=parse.parse('position=<{:>d},{:>d}> velocity=<{:>d},{:>d}>',string)
65+
stars.append(list(map(int,r)))
66+
67+
star_map=pathfinding.Graph()
68+
foriinrange (2*10**4):
69+
stars= [(x+vx,y+vy,vx,vy)forx,y,vx,vyinstars]
70+
vertices= [(x,y)forx,y,vx,vyinstars]
71+
72+
73+
# This was solved a bit manually
74+
# I noticed all coordinates would converge around 0 at some point
75+
# That point was around 10300 seconds
76+
# Then made a limit: all coordinates should be within 300 from zero
77+
# (my first test was actually 200, but that was gave no result)
78+
# This gave ~ 20 seconds of interesting time
79+
# At the end it was trial and error to find 10 240
80+
coords= [v[0]inrange(-300,300)forvinvertices]+ [v[1]inrange(-300,300)forvinvertices]
81+
82+
ifall(coords)andi==10239:
83+
star_map.vertices=vertices
84+
print (i+1)
85+
print (star_map.vertices_to_grid(wall=' '))
86+
87+
88+
89+
90+
# -------------------------------- Outputs / results -------------------------------- #
91+
92+
print ('Expected result : '+str(puzzle_expected_result))
93+
print ('Actual result : '+str(puzzle_actual_result))
94+
95+
96+
97+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp