Skip to content

Instantly share code, notes, and snippets.

@cjauvin
Created December 9, 2016 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjauvin/42468ba158508c329055721b206b560b to your computer and use it in GitHub Desktop.
Save cjauvin/42468ba158508c329055721b206b560b to your computer and use it in GitHub Desktop.
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