def test_second_example(self):

        groups = utils.group_lines(EXAMPLE_2)

        self.assertEqual(
            [day6.count_questions_part_2(g) for g in groups],
            [3, 0, 1, 1, 1]
        )

        self.assertEqual(day6.part_2(EXAMPLE_2), 6)
Exemple #2
0
def parse(lines):

    if isinstance(lines, str):
        lines = to_lines(lines)

    lines = group_lines(lines)

    decks = [player[1:] for player in lines]
    decks = [[int(card) for card in deck] for deck in decks]
    return decks
Exemple #3
0
def parse(lines):

    if isinstance(lines, str):
        lines = to_lines(lines)

    tiles = group_lines(lines)

    tiles = [Tile(tile_lines) for tile_lines in tiles]
    tiles = {tile.num: tile for tile in tiles}
    return tiles
Exemple #4
0
def parse(lines):

    if isinstance(lines, str):
        lines = to_lines(lines)

    (rules, your_ticket, nearby_tickets) = group_lines(lines)

    rules = [parse_rule(line) for line in rules]
    your_ticket = parse_ticket(your_ticket[1])
    nearby_tickets = [parse_ticket(line) for line in nearby_tickets[1:]]

    return rules, your_ticket, nearby_tickets
Exemple #5
0
def part_2(lines):
    groups = utils.group_lines(lines)
    return sum(count_questions_part_2(g) for g in groups)
def parse_rules_and_messages(lines):

    if isinstance(lines, str):
        lines = to_lines(lines)

    return group_lines(lines)