Solve 2016 days 6 to 8.
This commit is contained in:
53
2016/d8.py
Normal file
53
2016/d8.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from lib import *
|
||||
|
||||
data = open(0).read().strip()
|
||||
|
||||
cols = 50
|
||||
rows = 6
|
||||
pxs = []
|
||||
|
||||
def display(pxs):
|
||||
for r in range(rows):
|
||||
row = ""
|
||||
for c in range(cols):
|
||||
if (r, c) in pxs:
|
||||
row += "#"
|
||||
else:
|
||||
row += "."
|
||||
print(row)
|
||||
print()
|
||||
|
||||
for line in data.splitlines():
|
||||
if "rect" in line:
|
||||
col, row = str_to_ints(line)
|
||||
for r in range(row):
|
||||
for c in range(col):
|
||||
if r < rows and c < cols:
|
||||
pxs.append((r, c))
|
||||
elif "row" in line:
|
||||
npxs = []
|
||||
row, offset = str_to_ints(line)
|
||||
for (r, c) in pxs:
|
||||
if r == row:
|
||||
nc = (c + offset) % cols
|
||||
npxs.append((r, nc))
|
||||
else:
|
||||
npxs.append((r, c))
|
||||
pxs = npxs
|
||||
elif "column" in line:
|
||||
npxs = []
|
||||
col, offset = str_to_ints(line)
|
||||
for (r, c) in pxs:
|
||||
if c == col:
|
||||
nr = (r + offset) % rows
|
||||
npxs.append((nr, c))
|
||||
else:
|
||||
npxs.append((r, c))
|
||||
pxs = npxs
|
||||
else:
|
||||
assert False
|
||||
|
||||
pxs = list(set(pxs))
|
||||
|
||||
print(len(pxs))
|
||||
display(pxs) # EOARGPHYAO
|
||||
Reference in New Issue
Block a user