def parse(self, lines): size = len(lines)-2 grid = parse_grid(lines) constraints = { "top": {}, "right": {}, "bottom": {}, "left": {}, } for i in range(1, size+1): constraints['top'][i-1] = grid.pop((0, i), None) constraints['right'][i-1] = grid.pop((i, size+1), None) constraints['bottom'][i-1] = grid.pop((size+1, i), None) constraints['left'][i-1] = grid.pop((i, 0), None) grid = dict(((x-1, y-1), v) for (x, y), v in grid.items()) """ print size for key in constraints.keys(): print key, repr("".join(constraints[key][i] or "-" for i in range(size))) for i in range(size): for j in range(size): print grid[i, j], print """ return SkyScrappers(size, grid, constraints)
def parse(self, lines): rows = len(lines) cols = len(lines[0]) data = parser.parse_grid(lines) return Twist(rows, cols, data)
def parse(self, lines): rows = len(lines)/2 cols = len(lines[0])/2 grid = parser.parse_grid(lines) hlines = [(x/2, y/2) for y, x in grid if grid[y, x] in "_-"] vlines = [(x/2, y/2) for y, x in grid if grid[y, x] == "|"] return Loop(rows, cols, hlines, vlines)
def parse(self, lines): data = parser.parse_grid(lines) m = utils.dict2matrix(data) d = [row[::2] for row in m[::2]] twist = Twist(len(d), len(d[0]), utils.matrix2dict(d)) markers = { "|": [0, -1, 0, 1], "-": [-1, 0, 1, 0], "\\": [-1, -1, 1, 1], "/": [1, -1, -1, 1] } connections = [] for (y, x), v in sorted(data.items()): if v in markers: dx1, dy1, dx2, dy2 = markers[v] x1, y1 = (x+dx1)/2, (y+dy1)/2 x2, y2 = (x+dx2)/2, (y+dy2)/2 c = (y1, x1), (y2, x2) connections.append(c) return TwistSolution(twist, connections)