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.

Add solution for 2016/08

+227
+33
2016/day08.py
··· 1 + import re 2 + import fileinput 3 + from utils import parse_line 4 + 5 + WIDTH = 50 6 + HEIGHT = 6 7 + SCREEN = [[False for _ in range(WIDTH)] for _ in range(HEIGHT)] 8 + 9 + for line in fileinput.input(): 10 + if line.startswith('rect'): 11 + a, b = parse_line(r'rect (\d+)x(\d+)', line) 12 + 13 + for y in range(b): 14 + for x in range(a): 15 + SCREEN[y][x] = True 16 + 17 + else: 18 + rc, n, offset = parse_line(r'rotate (\w+) .=(\d+) by (\d+)', line) 19 + 20 + if rc == 'row': 21 + temp = SCREEN[n][:] 22 + for i, x in enumerate(temp): 23 + SCREEN[n][(offset+i) % WIDTH] = x 24 + 25 + else: 26 + temp = [row[n] for row in SCREEN] 27 + for i, x in enumerate(temp): 28 + SCREEN[(offset+i) % HEIGHT][n] = x 29 + 30 + print "Number of lit pixels: %i" % sum(sum(row) for row in SCREEN) 31 + 32 + for row in SCREEN: 33 + print ''.join('#' if x else ' ' for x in row)
+194
2016/input08.txt
··· 1 + rect 1x1 2 + rotate row y=0 by 7 3 + rect 1x1 4 + rotate row y=0 by 5 5 + rect 1x1 6 + rotate row y=0 by 5 7 + rect 1x1 8 + rotate row y=0 by 2 9 + rect 1x1 10 + rotate row y=0 by 3 11 + rect 1x1 12 + rotate row y=0 by 5 13 + rect 1x1 14 + rotate row y=0 by 3 15 + rect 1x1 16 + rotate row y=0 by 2 17 + rect 1x1 18 + rotate row y=0 by 3 19 + rect 2x1 20 + rotate row y=0 by 7 21 + rect 6x1 22 + rotate row y=0 by 3 23 + rect 2x1 24 + rotate row y=0 by 2 25 + rect 1x2 26 + rotate row y=1 by 10 27 + rotate row y=0 by 3 28 + rotate column x=0 by 1 29 + rect 2x1 30 + rotate column x=20 by 1 31 + rotate column x=15 by 1 32 + rotate column x=5 by 1 33 + rotate row y=1 by 5 34 + rotate row y=0 by 2 35 + rect 1x2 36 + rotate row y=0 by 5 37 + rotate column x=0 by 1 38 + rect 4x1 39 + rotate row y=2 by 15 40 + rotate row y=0 by 5 41 + rotate column x=0 by 1 42 + rect 4x1 43 + rotate row y=2 by 5 44 + rotate row y=0 by 5 45 + rotate column x=0 by 1 46 + rect 4x1 47 + rotate row y=2 by 10 48 + rotate row y=0 by 10 49 + rotate column x=8 by 1 50 + rotate column x=5 by 1 51 + rotate column x=0 by 1 52 + rect 9x1 53 + rotate column x=27 by 1 54 + rotate row y=0 by 5 55 + rotate column x=0 by 1 56 + rect 4x1 57 + rotate column x=42 by 1 58 + rotate column x=40 by 1 59 + rotate column x=22 by 1 60 + rotate column x=17 by 1 61 + rotate column x=12 by 1 62 + rotate column x=7 by 1 63 + rotate column x=2 by 1 64 + rotate row y=3 by 10 65 + rotate row y=2 by 5 66 + rotate row y=1 by 3 67 + rotate row y=0 by 10 68 + rect 1x4 69 + rotate column x=37 by 2 70 + rotate row y=3 by 18 71 + rotate row y=2 by 30 72 + rotate row y=1 by 7 73 + rotate row y=0 by 2 74 + rotate column x=13 by 3 75 + rotate column x=12 by 1 76 + rotate column x=10 by 1 77 + rotate column x=7 by 1 78 + rotate column x=6 by 3 79 + rotate column x=5 by 1 80 + rotate column x=3 by 3 81 + rotate column x=2 by 1 82 + rotate column x=0 by 1 83 + rect 14x1 84 + rotate column x=38 by 3 85 + rotate row y=3 by 12 86 + rotate row y=2 by 10 87 + rotate row y=0 by 10 88 + rotate column x=7 by 1 89 + rotate column x=5 by 1 90 + rotate column x=2 by 1 91 + rotate column x=0 by 1 92 + rect 9x1 93 + rotate row y=4 by 20 94 + rotate row y=3 by 25 95 + rotate row y=2 by 10 96 + rotate row y=0 by 15 97 + rotate column x=12 by 1 98 + rotate column x=10 by 1 99 + rotate column x=8 by 3 100 + rotate column x=7 by 1 101 + rotate column x=5 by 1 102 + rotate column x=3 by 3 103 + rotate column x=2 by 1 104 + rotate column x=0 by 1 105 + rect 14x1 106 + rotate column x=34 by 1 107 + rotate row y=1 by 45 108 + rotate column x=47 by 1 109 + rotate column x=42 by 1 110 + rotate column x=19 by 1 111 + rotate column x=9 by 2 112 + rotate row y=4 by 7 113 + rotate row y=3 by 20 114 + rotate row y=0 by 7 115 + rotate column x=5 by 1 116 + rotate column x=3 by 1 117 + rotate column x=2 by 1 118 + rotate column x=0 by 1 119 + rect 6x1 120 + rotate row y=4 by 8 121 + rotate row y=3 by 5 122 + rotate row y=1 by 5 123 + rotate column x=5 by 1 124 + rotate column x=4 by 1 125 + rotate column x=3 by 2 126 + rotate column x=2 by 1 127 + rotate column x=1 by 3 128 + rotate column x=0 by 1 129 + rect 6x1 130 + rotate column x=36 by 3 131 + rotate column x=25 by 3 132 + rotate column x=18 by 3 133 + rotate column x=11 by 3 134 + rotate column x=3 by 4 135 + rotate row y=4 by 5 136 + rotate row y=3 by 5 137 + rotate row y=2 by 8 138 + rotate row y=1 by 8 139 + rotate row y=0 by 3 140 + rotate column x=3 by 4 141 + rotate column x=0 by 4 142 + rect 4x4 143 + rotate row y=4 by 10 144 + rotate row y=3 by 20 145 + rotate row y=1 by 10 146 + rotate row y=0 by 10 147 + rotate column x=8 by 1 148 + rotate column x=7 by 1 149 + rotate column x=6 by 1 150 + rotate column x=5 by 1 151 + rotate column x=3 by 1 152 + rotate column x=2 by 1 153 + rotate column x=1 by 1 154 + rotate column x=0 by 1 155 + rect 9x1 156 + rotate row y=0 by 40 157 + rotate column x=44 by 1 158 + rotate column x=35 by 5 159 + rotate column x=18 by 5 160 + rotate column x=15 by 3 161 + rotate column x=10 by 5 162 + rotate row y=5 by 15 163 + rotate row y=4 by 10 164 + rotate row y=3 by 40 165 + rotate row y=2 by 20 166 + rotate row y=1 by 45 167 + rotate row y=0 by 35 168 + rotate column x=48 by 1 169 + rotate column x=47 by 5 170 + rotate column x=46 by 5 171 + rotate column x=45 by 1 172 + rotate column x=43 by 1 173 + rotate column x=40 by 1 174 + rotate column x=38 by 2 175 + rotate column x=37 by 3 176 + rotate column x=36 by 2 177 + rotate column x=32 by 2 178 + rotate column x=31 by 2 179 + rotate column x=28 by 1 180 + rotate column x=23 by 3 181 + rotate column x=22 by 3 182 + rotate column x=21 by 5 183 + rotate column x=20 by 1 184 + rotate column x=18 by 1 185 + rotate column x=17 by 3 186 + rotate column x=13 by 1 187 + rotate column x=10 by 1 188 + rotate column x=8 by 1 189 + rotate column x=7 by 5 190 + rotate column x=6 by 5 191 + rotate column x=5 by 1 192 + rotate column x=3 by 5 193 + rotate column x=2 by 5 194 + rotate column x=1 by 5