Roderic Day pirms 4 gadiem
vecāks
revīzija
fa75ab17cd
2 mainītis faili ar 46 papildinājumiem un 0 dzēšanām
  1. +8
    -0
      toolkit.py
  2. +38
    -0
      y2016/p08.py

+ 8
- 0
toolkit.py Parādīt failu

@@ -71,3 +71,11 @@ def md5gen(template, pattern=r'.+', batch=6000):
args = [c for s in strings for c in ['-s', s]]
out = subprocess.check_output(['md5'] + args).decode()
yield from re.findall(rf'"(.+)"\) = ({pattern})', out)


def interpret(string, globals):
fn, *args = (
x if x.replace('_', '').isalpha() else eval(x)
for x in string.split()
)
globals[fn](**dict(zip(*[iter(args)] * 2)))

+ 38
- 0
y2016/p08.py Parādīt failu

@@ -0,0 +1,38 @@
import re
import sys

import toolkit


def rect(w, h):
for y in range(h):
for x in range(w):
screen[y][x] = '#'


def rotate_row(y, by):
screen[y] = screen[y][-by:] + screen[y][:-by]


def rotate_column(x, by):
tmp = list(zip(*screen))
tmp[x] = tmp[x][-by:] + tmp[x][:-by]
screen[:] = list(map(list, zip(*tmp)))


def display(screen):
print('\n'.join(''.join(line) for line in screen) + '\n')


W, H, text = 50, 6, sys.stdin.read()
screen = [[' ' for _ in range(W)] for _ in range(H)]

text = text.replace('rotate ', 'rotate_')
text = text.replace('=', ' ')
text = re.sub(r'(\d+)x(\d+)', r'w \1 h \2', text)

for line in text.splitlines():
toolkit.interpret(line, globals())

print(sum(row.count('#') for row in screen))
display(screen)

Notiek ielāde…
Atcelt
Saglabāt