-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_13.py
124 lines (89 loc) · 17.2 KB
/
day_13.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
s_input = '''1,380,379,385,1008,2751,248387,381,1005,381,12,99,109,2752,1102,1,0,383,1101,0,0,382,21001,382,0,1,20101,0,383,2,21102,1,37,0,1105,1,578,4,382,4,383,204,1,1001,382,1,382,1007,382,44,381,1005,381,22,1001,383,1,383,1007,383,24,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1105,1,161,107,1,392,381,1006,381,161,1102,-1,1,384,1106,0,119,1007,392,42,381,1006,381,161,1102,1,1,384,21001,392,0,1,21101,0,22,2,21102,1,0,3,21101,0,138,0,1105,1,549,1,392,384,392,20101,0,392,1,21102,22,1,2,21102,3,1,3,21101,0,161,0,1106,0,549,1102,0,1,384,20001,388,390,1,20101,0,389,2,21102,180,1,0,1106,0,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,21001,389,0,2,21101,0,205,0,1106,0,393,1002,390,-1,390,1101,1,0,384,20102,1,388,1,20001,389,391,2,21102,228,1,0,1105,1,578,1206,1,261,1208,1,2,381,1006,381,253,20102,1,388,1,20001,389,391,2,21102,1,253,0,1105,1,393,1002,391,-1,391,1102,1,1,384,1005,384,161,20001,388,390,1,20001,389,391,2,21102,1,279,0,1105,1,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,0,304,0,1106,0,393,1002,390,-1,390,1002,391,-1,391,1102,1,1,384,1005,384,161,21002,388,1,1,21002,389,1,2,21102,0,1,3,21101,0,338,0,1106,0,549,1,388,390,388,1,389,391,389,21001,388,0,1,20102,1,389,2,21101,4,0,3,21101,0,365,0,1105,1,549,1007,389,23,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,412,20,19,1,1,22,109,3,22102,1,-2,1,22101,0,-1,2,21101,0,0,3,21101,0,414,0,1105,1,549,21201,-2,0,1,21201,-1,0,2,21102,429,1,0,1106,0,601,2101,0,1,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2105,1,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,21202,-3,1,-7,109,-8,2106,0,0,109,4,1202,-2,44,566,201,-3,566,566,101,639,566,566,2101,0,-1,0,204,-3,204,-2,204,-1,109,-4,2105,1,0,109,3,1202,-1,44,594,201,-2,594,594,101,639,594,594,20102,1,0,-2,109,-3,2105,1,0,109,3,22102,24,-2,1,22201,1,-1,1,21101,0,541,2,21102,695,1,3,21102,1056,1,4,21102,1,630,0,1105,1,456,21201,1,1695,-2,109,-3,2105,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,2,2,2,2,0,0,2,2,2,2,0,2,0,0,2,2,0,2,0,2,0,2,2,0,2,2,0,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62,84,16,88,74,91,41,43,63,88,93,37,54,44,64,64,96,76,70,47,26,97,18,23,87,62,27,64,82,34,28,64,69,9,44,64,27,39,70,9,27,12,9,85,69,96,54,28,47,72,1,87,63,94,3,70,28,95,3,54,82,13,39,18,13,3,73,7,46,98,72,96,31,61,60,6,50,96,32,94,59,34,32,87,70,34,48,19,78,7,94,42,6,40,69,72,44,76,84,60,66,86,74,40,40,86,48,48,58,31,46,96,4,94,51,76,2,39,89,52,58,4,88,26,31,74,5,53,97,81,38,41,93,90,11,8,89,92,39,71,33,64,9,70,6,71,89,66,8,2,48,78,4,22,61,25,51,79,62,97,87,22,62,95,17,98,50,45,87,41,8,44,75,26,65,3,96,78,10,74,52,55,66,88,10,17,9,15,60,79,6,11,87,36,61,48,36,56,85,95,87,97,67,78,81,69,71,26,65,54,69,89,72,9,83,17,97,59,75,40,90,6,17,69,84,97,69,39,67,49,97,11,37,48,51,97,37,48,41,26,93,82,5,29,63,33,28,55,95,1,9,85,72,52,11,8,77,68,6,56,45,55,59,35,98,24,93,3,82,32,13,79,31,64,45,18,37,4,13,96,24,52,61,94,29,48,17,36,63,22,95,8,75,31,81,49,4,80,78,19,85,15,92,29,31,33,70,60,59,71,25,23,70,23,26,35,60,60,11,20,31,8,37,23,48,93,67,56,95,6,76,41,91,14,63,44,97,67,11,54,40,52,56,49,56,64,33,84,86,14,80,4,69,15,85,83,84,59,68,92,39,25,30,15,45,59,48,12,25,39,59,81,62,31,66,90,41,95,5,60,68,37,92,51,47,89,73,68,40,65,63,87,77,4,74,45,2,79,45,19,50,35,50,51,18,65,21,91,56,20,58,89,18,12,21,59,52,56,69,69,81,12,93,89,43,96,43,27,23,65,64,37,23,17,55,1,20,45,62,2,50,2,67,46,73,32,93,79,8,22,23,87,70,52,42,98,73,94,2,23,14,70,16,86,88,21,11,25,16,14,80,84,17,40,83,17,3,8,16,70,37,76,89,68,34,37,37,48,77,93,17,47,7,77,49,27,48,6,65,84,81,57,96,90,94,31,17,46,59,8,69,92,79,91,14,60,91,49,83,11,65,11,96,90,84,21,40,8,94,8,23,79,20,2,88,42,86,80,4,85,51,34,77,75,78,94,26,83,16,70,45,31,70,96,48,32,76,93,66,9,73,63,42,84,41,1,19,79,28,81,71,76,26,76,74,35,39,52,18,17,81,23,76,14,94,98,72,67,62,39,54,30,8,24,43,53,69,7,92,65,93,71,58,26,73,52,75,93,8,10,71,87,12,4,56,4,70,72,83,24,55,53,34,89,75,45,95,29,96,4,61,76,3,69,10,36,10,79,41,18,74,94,96,32,39,12,32,6,32,93,69,52,75,76,22,74,45,11,51,22,79,96,71,68,9,72,48,77,11,67,50,56,61,63,74,81,48,31,72,35,59,41,4,85,86,3,23,64,79,10,85,97,67,66,87,41,48,17,70,82,8,95,42,36,30,94,57,94,34,88,95,64,64,17,13,92,9,53,52,53,98,21,87,13,34,83,2,72,74,23,87,61,16,20,28,46,57,82,37,83,74,79,7,15,15,59,28,31,16,6,22,66,41,93,82,71,96,41,32,4,30,50,52,30,17,92,71,10,59,73,91,39,20,19,53,15,24,39,79,34,29,41,91,57,49,39,24,12,79,24,63,66,41,15,54,94,90,37,4,65,82,54,28,46,50,64,22,28,60,58,8,41,68,41,28,2,19,9,2,11,87,76,10,63,45,72,12,84,12,35,50,9,46,28,40,29,80,42,39,80,77,37,6,11,13,24,95,60,65,18,97,86,6,64,67,53,18,40,91,98,48,49,47,31,76,68,74,93,14,45,25,29,68,2,49,53,56,87,9,87,87,64,14,69,7,55,55,63,48,78,86,73,45,31,61,83,93,64,68,22,58,80,10,98,63,11,38,64,82,61,8,61,51,39,5,14,69,65,64,90,61,55,37,41,31,40,64,32,27,15,19,58,33,38,90,39,6,13,14,89,52,84,76,1,96,45,5,61,69,44,43,98,80,1,72,63,23,10,77,57,50,74,93,7,15,37,34,40,88,7,248387'''
s_input = '''1,380,379,385,1008,2751,248387,381,1005,381,12,99,109,2752,1102,1,0,383,1101,0,0,382,21001,382,0,1,20101,0,383,2,21102,1,37,0,1105,1,578,4,382,4,383,204,1,1001,382,1,382,1007,382,44,381,1005,381,22,1001,383,1,383,1007,383,24,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1105,1,161,107,1,392,381,1006,381,161,1102,-1,1,384,1106,0,119,1007,392,42,381,1006,381,161,1102,1,1,384,21001,392,0,1,21101,0,22,2,21102,1,0,3,21101,0,138,0,1105,1,549,1,392,384,392,20101,0,392,1,21102,22,1,2,21102,3,1,3,21101,0,161,0,1106,0,549,1102,0,1,384,20001,388,390,1,20101,0,389,2,21102,180,1,0,1106,0,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,21001,389,0,2,21101,0,205,0,1106,0,393,1002,390,-1,390,1101,1,0,384,20102,1,388,1,20001,389,391,2,21102,228,1,0,1105,1,578,1206,1,261,1208,1,2,381,1006,381,253,20102,1,388,1,20001,389,391,2,21102,1,253,0,1105,1,393,1002,391,-1,391,1102,1,1,384,1005,384,161,20001,388,390,1,20001,389,391,2,21102,1,279,0,1105,1,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,0,304,0,1106,0,393,1002,390,-1,390,1002,391,-1,391,1102,1,1,384,1005,384,161,21002,388,1,1,21002,389,1,2,21102,0,1,3,21101,0,338,0,1106,0,549,1,388,390,388,1,389,391,389,21001,388,0,1,20102,1,389,2,21101,4,0,3,21101,0,365,0,1105,1,549,1007,389,23,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,412,20,19,1,1,22,109,3,22102,1,-2,1,22101,0,-1,2,21101,0,0,3,21101,0,414,0,1105,1,549,21201,-2,0,1,21201,-1,0,2,21102,429,1,0,1106,0,601,2101,0,1,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2105,1,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,21202,-3,1,-7,109,-8,2106,0,0,109,4,1202,-2,44,566,201,-3,566,566,101,639,566,566,2101,0,-1,0,204,-3,204,-2,204,-1,109,-4,2105,1,0,109,3,1202,-1,44,594,201,-2,594,594,101,639,594,594,20102,1,0,-2,109,-3,2105,1,0,109,3,22102,24,-2,1,22201,1,-1,1,21101,0,541,2,21102,695,1,3,21102,1056,1,4,21102,1,630,0,1105,1,456,21201,1,1695,-2,109,-3,2105,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,2,2,2,2,0,0,2,2,2,2,0,2,0,0,2,2,0,2,0,2,0,2,2,0,2,2,0,2,0,2,2,2,2,2,2,2,0,2,2,0,1,1,0,0,2,2,0,2,2,0,2,2,2,2,2,0,2,2,2,0,2,2,0,2,2,2,2,2,0,0,2,2,2,0,0,2,0,0,2,0,0,2,2,0,1,1,0,0,2,2,2,2,2,0,0,0,2,0,2,0,2,2,0,2,0,2,2,0,2,2,0,2,2,0,2,0,2,0,2,2,2,2,0,2,2,2,0,0,1,1,0,0,2,2,2,2,2,2,2,0,2,2,0,0,2,2,0,0,0,0,0,2,0,2,0,0,2,0,2,0,2,0,0,2,2,0,0,0,2,0,0,0,1,1,0,0,0,2,2,0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,0,2,2,0,0,2,2,2,2,0,0,0,0,0,0,2,2,2,0,1,1,0,0,2,0,0,2,0,2,0,2,0,0,2,2,2,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1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,43,34,19,38,49,68,88,56,54,52,29,1,43,97,67,20,16,38,59,54,42,95,82,45,46,6,37,75,44,45,68,23,64,81,23,20,23,7,16,74,92,42,42,95,63,5,59,5,48,76,2,35,18,58,7,86,31,20,12,37,9,44,81,62,26,39,1,28,2,10,34,9,83,73,16,43,88,47,40,54,29,77,56,97,98,94,62,84,16,88,74,91,41,43,63,88,93,37,54,44,64,64,96,76,70,47,26,97,18,23,87,62,27,64,82,34,28,64,69,9,44,64,27,39,70,9,27,12,9,85,69,96,54,28,47,72,1,87,63,94,3,70,28,95,3,54,82,13,39,18,13,3,73,7,46,98,72,96,31,61,60,6,50,96,32,94,59,34,32,87,70,34,48,19,78,7,94,42,6,40,69,72,44,76,84,60,66,86,74,40,40,86,48,48,58,31,46,96,4,94,51,76,2,39,89,52,58,4,88,26,31,74,5,53,97,81,38,41,93,90,11,8,89,92,39,71,33,64,9,70,6,71,89,66,8,2,48,78,4,22,61,25,51,79,62,97,87,22,62,95,17,98,50,45,87,41,8,44,75,26,65,3,96,78,10,74,52,55,66,88,10,17,9,15,60,79,6,11,87,36,61,48,36,56,85,95,87,97,67,78,81,69,71,26,65,54,69,89,72,9,83,17,97,59,75,40,90,6,17,69,84,97,69,39,67,49,97,11,37,48,51,97,37,48,41,26,93,82,5,29,63,33,28,55,95,1,9,85,72,52,11,8,77,68,6,56,45,55,59,35,98,24,93,3,82,32,13,79,31,64,45,18,37,4,13,96,24,52,61,94,29,48,17,36,63,22,95,8,75,31,81,49,4,80,78,19,85,15,92,29,31,33,70,60,59,71,25,23,70,23,26,35,60,60,11,20,31,8,37,23,48,93,67,56,95,6,76,41,91,14,63,44,97,67,11,54,40,52,56,49,56,64,33,84,86,14,80,4,69,15,85,83,84,59,68,92,39,25,30,15,45,59,48,12,25,39,59,81,62,31,66,90,41,95,5,60,68,37,92,51,47,89,73,68,40,65,63,87,77,4,74,45,2,79,45,19,50,35,50,51,18,65,21,91,56,20,58,89,18,12,21,59,52,56,69,69,81,12,93,89,43,96,43,27,23,65,64,37,23,17,55,1,20,45,62,2,50,2,67,46,73,32,93,79,8,22,23,87,70,52,42,98,73,94,2,23,14,70,16,86,88,21,11,25,16,14,80,84,17,40,83,17,3,8,16,70,37,76,89,68,34,37,37,48,77,93,17,47,7,77,49,27,48,6,65,84,81,57,96,90,94,31,17,46,59,8,69,92,79,91,14,60,91,49,83,11,65,11,96,90,84,21,40,8,94,8,23,79,20,2,88,42,86,80,4,85,51,34,77,75,78,94,26,83,16,70,45,31,70,96,48,32,76,93,66,9,73,63,42,84,41,1,19,79,28,81,71,76,26,76,74,35,39,52,18,17,81,23,76,14,94,98,72,67,62,39,54,30,8,24,43,53,69,7,92,65,93,71,58,26,73,52,75,93,8,10,71,87,12,4,56,4,70,72,83,24,55,53,34,89,75,45,95,29,96,4,61,76,3,69,10,36,10,79,41,18,74,94,96,32,39,12,32,6,32,93,69,52,75,76,22,74,45,11,51,22,79,96,71,68,9,72,48,77,11,67,50,56,61,63,74,81,48,31,72,35,59,41,4,85,86,3,23,64,79,10,85,97,67,66,87,41,48,17,70,82,8,95,42,36,30,94,57,94,34,88,95,64,64,17,13,92,9,53,52,53,98,21,87,13,34,83,2,72,74,23,87,61,16,20,28,46,57,82,37,83,74,79,7,15,15,59,28,31,16,6,22,66,41,93,82,71,96,41,32,4,30,50,52,30,17,92,71,10,59,73,91,39,20,19,53,15,24,39,79,34,29,41,91,57,49,39,24,12,79,24,63,66,41,15,54,94,90,37,4,65,82,54,28,46,50,64,22,28,60,58,8,41,68,41,28,2,19,9,2,11,87,76,10,63,45,72,12,84,12,35,50,9,46,28,40,29,80,42,39,80,77,37,6,11,13,24,95,60,65,18,97,86,6,64,67,53,18,40,91,98,48,49,47,31,76,68,74,93,14,45,25,29,68,2,49,53,56,87,9,87,87,64,14,69,7,55,55,63,48,78,86,73,45,31,61,83,93,64,68,22,58,80,10,98,63,11,38,64,82,61,8,61,51,39,5,14,69,65,64,90,61,55,37,41,31,40,64,32,27,15,19,58,33,38,90,39,6,13,14,89,52,84,76,1,96,45,5,61,69,44,43,98,80,1,72,63,23,10,77,57,50,74,93,7,15,37,34,40,88,7,248387'''
from intcode_computer import ProgramExecutor
from collections import namedtuple
from types import SimpleNamespace
TileTypes = namedtuple('TileTypes', ['EMPTY', 'WALL', 'BLOCK', 'HORIZONTAL_PADDLE', 'BALL'])
TILE_TYPES = TileTypes(
EMPTY = 0,
WALL = 1,
BLOCK = 2,
HORIZONTAL_PADDLE = 3,
BALL = 4
)
def create_arcade_grid():
screen_size = (44, 24)
grid = [[TILE_TYPES.EMPTY] * screen_size[0] for _ in range(screen_size[1])]
return grid
def update_grid(grid, instructions):
score = None
for idx in range(0, len(instructions), 3):
x, y, tile = (instructions[idx], instructions[idx + 1], instructions[idx + 2])
if x == -1 and y == 0:
score = tile
else:
grid[y][x] = tile
return score
def grid_to_string(grid):
res = []
for row in grid:
row_str = ''.join(str(item) for item in row)
row_str = row_str.replace('0', ' ').replace('1', '|').replace('2', '*').replace('3', '_').replace('4', 'o')
res.append(row_str)
return '\n'.join(res)
program = list(map(int, s_input.split(',')))
arcade = ProgramExecutor(program)
arcade.run()
screen_commands = arcade.result
def count_blocks(grid):
return sum(row.count(TILE_TYPES.BLOCK) for row in grid)
grid = create_arcade_grid()
update_grid(grid, arcade.result)
print('Answer 1', count_blocks(grid))
def find_ball_and_paddle_positions(grid):
ball_pos = None
paddle_pos = None
for row_index, row in enumerate(grid):
try:
index = row.index(TILE_TYPES.BALL)
ball_pos = SimpleNamespace(x=index, y=row_index)
except ValueError:
pass
try:
index = row.index(TILE_TYPES.HORIZONTAL_PADDLE)
paddle_pos = SimpleNamespace(x=index, y=row_index)
except ValueError:
pass
return [ball_pos, paddle_pos]
program2 = list(program)
program2[0] = 2
score = 0
arcade_game = ProgramExecutor(program2)
ball_vec = 0
prev_ball_x = None
grid = create_arcade_grid()
grid[-2] = [TILE_TYPES.WALL] * len(grid[-2])
last_score = 0
while arcade_game.state != ProgramExecutor.STATES['HALTED']:
arcade_game.run()
score = update_grid(grid, arcade_game.result)
if score:
last_score = score
arcade_game.clear_output()
ball_pos, paddle_pos = find_ball_and_paddle_positions(grid)
if prev_ball_x:
ball_vec = ball_pos.x - prev_ball_x
prev_ball_x = ball_pos.x
if ball_pos.x < paddle_pos.x:
# arcade_game.add_inputs(-1)
pass
elif ball_pos.x > paddle_pos.x:
# arcade_game.add_inputs(1)
pass
else:
# arcade_game.add_inputs(ball_vec)
pass
arcade_game.add_inputs(0)
# print(grid_to_string(grid))
print('Block count', count_blocks(grid))
print('Answer 2', score)