import os # NOQA import sys # NOQA import re # NOQA import math # NOQA import copy # NOQA import fileinput from collections import Counter, defaultdict, deque, namedtuple # NOQA from utils import parse_nums, mul, print_grid, transposed, rotated, Point, new_table tot = 0 res = [] board = new_table('.', width=10, height=10) tiles = {} curr = 0 sy = 0 MONSTER = """ # # ## ## ### # # # # # # """ for y, line in enumerate(fileinput.input()): line = line.strip() nums = parse_nums(line) if not line: tiles[curr] = copy.deepcopy(board) board = new_table('.', width=10, height=10)
from utils import chunks, gcd, lcm, print_grid, min_max_xy # NOQA from utils import new_table, transposed, rotated # NOQA from utils import md5, sha256, knot_hash # NOQA from utils import VOWELS, CONSONANTS # NOQA from utils import Point, DIRS, DIRS_4, DIRS_8 # NOQA # N (0, 1) -> E (1, 0) -> S (0, -1) -> W (-1, 0) # Itertools Functions: # product('ABCD', repeat=2) AA AB AC AD BA BB BC BD CA CB CC CD DA DB DC DD # permutations('ABCD', 2) AB AC AD BA BC BD CA CB CD DA DB DC # combinations('ABCD', 2) AB AC AD BC BD CD # combinations_with_replacement('ABCD', 2) AA AB AC AD BB BC BD CC CD DD tot = 0 res = [] board = {} table = new_table(None, width=2, height=4) # Uncomment for multi-group style inputs. :c # data = ''.join([line for line in fileinput.input()]) # groups = [g.split('\n') for g in data.split('\n\n')] for y, line in enumerate(fileinput.input()): line = line.strip() nums = parse_nums(line) data = parse_line(r'', line) nums = [int(x) for x in line.split(',')] for x, c in enumerate(line): board[Point(x, y)] = c if y == 0:
RULES = {} for line in fileinput.input(): rule_in, rule_out = line.strip().split(' => ') # Build all rule rotations and reflections grid = [list(x) for x in rule_in.split('/')] n = 2 if rule_in.count('/') == 1 else 3 for _ in range(4): norm = ''.join(''.join(p) for p in grid) refl = ''.join(''.join(p[::-1]) for p in grid) RULES[norm] = RULES[refl] = rule_out.replace('/', '') rotated = new_table(None, width=n, height=n) for y in range(n): for x in range(n): rotated[y][x] = grid[n - x - 1][y] grid = rotated SUBGRIDS = Counter() SUBGRIDS['.#...####'] += 1 for it in range(18): # Build up our list of subgrids if it % 3 == 0: GRIDS = {} for key in SUBGRIDS: