Browse Source

Day 8

master
Chris Smith 7 years ago
parent
commit
73b7fd0fef
2 changed files with 174 additions and 0 deletions
  1. 21
    0
      08.py
  2. 153
    0
      08.txt

+ 21
- 0
08.py View File

@@ -0,0 +1,21 @@
1
+#!/usr/bin/python3
2
+
3
+import re
4
+import numpy as np
5
+
6
+with open('08.txt', 'r') as file:
7
+    lines = list(map(str.strip, file.readlines()))
8
+    lights = np.zeros((6, 50), dtype=bool)
9
+    for line in lines:
10
+        words = line.split(' ')
11
+        i, j = map(int, re.search(r'([0-9]+)(?: by |x)([0-9]+)', line).groups())
12
+        if words[0] == 'rect':
13
+            lights[:j, :i] = 1
14
+        elif words[1] == 'row':
15
+            lights[i] = np.roll(lights[i], j)
16
+        else:
17
+            lights[:,i] = np.roll(lights[:,i], j)
18
+        
19
+    print("Part one: %s" % np.sum(lights))
20
+    print("Part two:")
21
+    print('\n'.join(''.join('\u2588' if p else ' '  for p in row) for row in lights))

+ 153
- 0
08.txt View File

@@ -0,0 +1,153 @@
1
+rect 1x1
2
+rotate row y=0 by 2
3
+rect 1x1
4
+rotate row y=0 by 5
5
+rect 1x1
6
+rotate row y=0 by 3
7
+rect 1x1
8
+rotate row y=0 by 3
9
+rect 2x1
10
+rotate row y=0 by 5
11
+rect 1x1
12
+rotate row y=0 by 5
13
+rect 4x1
14
+rotate row y=0 by 2
15
+rect 1x1
16
+rotate row y=0 by 2
17
+rect 1x1
18
+rotate row y=0 by 5
19
+rect 4x1
20
+rotate row y=0 by 3
21
+rect 2x1
22
+rotate row y=0 by 5
23
+rect 4x1
24
+rotate row y=0 by 2
25
+rect 1x2
26
+rotate row y=1 by 6
27
+rotate row y=0 by 2
28
+rect 1x2
29
+rotate column x=32 by 1
30
+rotate column x=23 by 1
31
+rotate column x=13 by 1
32
+rotate row y=0 by 6
33
+rotate column x=0 by 1
34
+rect 5x1
35
+rotate row y=0 by 2
36
+rotate column x=30 by 1
37
+rotate row y=1 by 20
38
+rotate row y=0 by 18
39
+rotate column x=13 by 1
40
+rotate column x=10 by 1
41
+rotate column x=7 by 1
42
+rotate column x=2 by 1
43
+rotate column x=0 by 1
44
+rect 17x1
45
+rotate column x=16 by 3
46
+rotate row y=3 by 7
47
+rotate row y=0 by 5
48
+rotate column x=2 by 1
49
+rotate column x=0 by 1
50
+rect 4x1
51
+rotate column x=28 by 1
52
+rotate row y=1 by 24
53
+rotate row y=0 by 21
54
+rotate column x=19 by 1
55
+rotate column x=17 by 1
56
+rotate column x=16 by 1
57
+rotate column x=14 by 1
58
+rotate column x=12 by 2
59
+rotate column x=11 by 1
60
+rotate column x=9 by 1
61
+rotate column x=8 by 1
62
+rotate column x=7 by 1
63
+rotate column x=6 by 1
64
+rotate column x=4 by 1
65
+rotate column x=2 by 1
66
+rotate column x=0 by 1
67
+rect 20x1
68
+rotate column x=47 by 1
69
+rotate column x=40 by 2
70
+rotate column x=35 by 2
71
+rotate column x=30 by 2
72
+rotate column x=10 by 3
73
+rotate column x=5 by 3
74
+rotate row y=4 by 20
75
+rotate row y=3 by 10
76
+rotate row y=2 by 20
77
+rotate row y=1 by 16
78
+rotate row y=0 by 9
79
+rotate column x=7 by 2
80
+rotate column x=5 by 2
81
+rotate column x=3 by 2
82
+rotate column x=0 by 2
83
+rect 9x2
84
+rotate column x=22 by 2
85
+rotate row y=3 by 40
86
+rotate row y=1 by 20
87
+rotate row y=0 by 20
88
+rotate column x=18 by 1
89
+rotate column x=17 by 2
90
+rotate column x=16 by 1
91
+rotate column x=15 by 2
92
+rotate column x=13 by 1
93
+rotate column x=12 by 1
94
+rotate column x=11 by 1
95
+rotate column x=10 by 1
96
+rotate column x=8 by 3
97
+rotate column x=7 by 1
98
+rotate column x=6 by 1
99
+rotate column x=5 by 1
100
+rotate column x=3 by 1
101
+rotate column x=2 by 1
102
+rotate column x=1 by 1
103
+rotate column x=0 by 1
104
+rect 19x1
105
+rotate column x=44 by 2
106
+rotate column x=40 by 3
107
+rotate column x=29 by 1
108
+rotate column x=27 by 2
109
+rotate column x=25 by 5
110
+rotate column x=24 by 2
111
+rotate column x=22 by 2
112
+rotate column x=20 by 5
113
+rotate column x=14 by 3
114
+rotate column x=12 by 2
115
+rotate column x=10 by 4
116
+rotate column x=9 by 3
117
+rotate column x=7 by 3
118
+rotate column x=3 by 5
119
+rotate column x=2 by 2
120
+rotate row y=5 by 10
121
+rotate row y=4 by 8
122
+rotate row y=3 by 8
123
+rotate row y=2 by 48
124
+rotate row y=1 by 47
125
+rotate row y=0 by 40
126
+rotate column x=47 by 5
127
+rotate column x=46 by 5
128
+rotate column x=45 by 4
129
+rotate column x=43 by 2
130
+rotate column x=42 by 3
131
+rotate column x=41 by 2
132
+rotate column x=38 by 5
133
+rotate column x=37 by 5
134
+rotate column x=36 by 5
135
+rotate column x=33 by 1
136
+rotate column x=28 by 1
137
+rotate column x=27 by 5
138
+rotate column x=26 by 5
139
+rotate column x=25 by 1
140
+rotate column x=23 by 5
141
+rotate column x=22 by 1
142
+rotate column x=21 by 2
143
+rotate column x=18 by 1
144
+rotate column x=17 by 3
145
+rotate column x=12 by 2
146
+rotate column x=11 by 2
147
+rotate column x=7 by 5
148
+rotate column x=6 by 5
149
+rotate column x=5 by 4
150
+rotate column x=3 by 5
151
+rotate column x=2 by 5
152
+rotate column x=1 by 3
153
+rotate column x=0 by 4

Loading…
Cancel
Save