def parse_input_as_tiles(text): tile_data = dict() for tile_str in safe_split(text, '\n\n'): tile_id_str, *tile_lines = safe_split(tile_str, '\n') tile_id = int(*re.match('Tile ([0-9]+):', tile_id_str).groups()) tile = Tile(tile_id, tile_lines) # top, right, bottom, left tile.borders = [Border(tile_lines[0], tile), Border(''.join([l[-1] for l in tile_lines]), tile), Border(tile_lines[-1][::-1], tile), Border(''.join([l[0] for l in tile_lines])[::-1], tile)] tile_data[tile_id] = tile return tile_data
def parse_ticket(ticket_line): return list(map(int, safe_split(ticket_line, ',')))
def parse_input(text): rule_lines, your_ticket_lines, nearby_ticket_lines = map( lambda t: safe_split(t, '\n'), safe_split(text, '\n\n')) return parse_rules(rule_lines), \ parse_ticket(your_ticket_lines[-1]), \ list(map(parse_ticket, nearby_ticket_lines[1:]))
def parse_input(text): rule_text, msg_text = safe_split(text, '\n\n') direct_rules, indirect_rules = parse_rules(safe_split(rule_text, '\n')) return direct_rules, indirect_rules, safe_split(msg_text, '\n')
def group_to_persons(group_text): yield from safe_split(group_text, '\n')
def text_to_groups(text): yield from safe_split(text, '\n\n')
def parse_decks(text): return [[int(nr_str) for nr_str in safe_split(deck_text, '\n')[1:]] for deck_text in safe_split(text, '\n\n')]
def parse_input(): return list(map(int, safe_split(read_input(), ',')))