Created
December 9, 2016 03:24
-
-
Save cjauvin/42468ba158508c329055721b206b560b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import re | |
def rect(a, b): | |
g[:b, :a] = 1 | |
def rotate_row(a, b): | |
g[a, :] = np.append(g[a, -b:], g[a, :-b]) | |
def rotate_col(a, b): | |
g[:, a] = np.append(g[-b:, a], g[:-b, a]) | |
# test | |
g = np.zeros((3, 7)) | |
rect(3, 2) | |
rotate_col(1, 1) | |
rotate_row(0, 4) | |
rotate_col(1, 1) | |
g = np.zeros((6, 50)) | |
for line in open('data/day8.txt'): | |
if not line.strip(): continue | |
ns = list(map(int, re.findall('\d+', line))) | |
if 'rect' in line: | |
rect(*ns) | |
elif 'row' in line: | |
rotate_row(*ns) | |
else: | |
rotate_col(*ns) | |
print(np.sum(g)) | |
print() | |
for i in range(6): | |
for j in range(50): | |
print('.' if g[i, j] else ' ', end='' if j < 49 else '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment