Exemple #1
0
def read_seats() -> List[Seat]:
    seat_list = []
    with open(get_file_name()) as file:
        for line in file:
            if line:
                seat_list.append(Seat(line))
    return seat_list
Exemple #2
0
def read_seat_layout() -> List[List[str]]:
    rows = []
    with open(get_file_name()) as file:
        for line in file:
            if line:
                rows.append(list(line.strip()))

    return rows
Exemple #3
0
def read_instructions() -> List[str]:
    instruction = []
    with open(get_file_name()) as file:
        for line in file:
            if line:
                instruction.append(line.strip())

    return instruction
Exemple #4
0
def read_passports() -> List[Passport]:
    password_list = []
    with open(get_file_name()) as file:
        content = file.read()
        for raw_pwd in content.split("\n\n"):
            fields = raw_pwd.replace('\n', ' ').split()
            password_list.append(Passport.from_field_list(fields))
    return password_list
Exemple #5
0
def read_data() -> List[int]:
    data = []
    with open(get_file_name()) as file:
        for line in file:
            if line:
                data.append(int(line))

    return data
Exemple #6
0
def read_adapters() -> List[int]:
    adapters = []
    with open(get_file_name()) as file:
        for line in file:
            if line:
                adapters.append(int(line))

    return adapters
Exemple #7
0
def read_instructions() -> List[Instruction]:
    instructions = []
    with open(get_file_name()) as file:
        for line in file:
            if line:
                (op, arg) = line.split()
                instructions.append(
                    Instruction(operation=op, argument=int(arg)))

    return instructions
Exemple #8
0
def read_input() -> ShuttleSearchInput:
    with open(get_file_name()) as file:
        earliest_ts = int(file.readline().strip())
        bus_list = file.readline().strip().split(',')
        bus_info_list = []
        for i, bus_id in enumerate(bus_list):
            if bus_id != 'x':
                bus_info = BusInfo(id=int(bus_id), num=i)
                bus_info_list.append(bus_info)

        return ShuttleSearchInput(earliest_ts, bus_info_list)
Exemple #9
0
def read_answers() -> List[List[Set]]:
    answer_list = []
    with open(get_file_name()) as file:
        content = file.read()
        for raw_answer in content.split("\n\n"):
            group_answers = []
            for individual_answer in raw_answer.split('\n'):
                if individual_answer:
                    group_answers.append(set(individual_answer))
            answer_list.append(group_answers)
    return answer_list
Exemple #10
0
def read_rules() -> BidirectionalWeightedGraph:
    rules = BidirectionalWeightedGraph()
    with open(get_file_name()) as file:
        for line in file:
            if line:
                (bag, content) = line.split(" bags contain ")
                if not content.startswith("no"):
                    containing_bags = content.split(", ")
                    for containing_bag in containing_bags:
                        bag_match = CONTAINING_BAG_RE.match(containing_bag)
                        if bag_match:
                            rules.add(bag, bag_match["bag"],
                                      int(bag_match["number"]))

    return rules
Exemple #11
0
def read_map() -> AreaMap:
    trajectory_map = []
    with open(get_file_name()) as file:
        for line in file:
            trajectory_map.append(line.strip())
    return trajectory_map
Exemple #12
0
def read_expense_report() -> List[int]:
    with open(get_file_name()) as file:
        return [int(line) for line in file]
Exemple #13
0
def read_input() -> List[int]:
    with open(get_file_name()) as file:
        input_split = file.readline().strip().split(',')
        return [int(s) for s in input_split]