Пример #1
0
    def __init__(self, map_file):
        self.map = []
        preprocessed_map = Helper.load_file(map_file)

        # Converting file into 2D array
        for line in preprocessed_map:
            self.map.append(list("".join([line])))
Пример #2
0
    def __init__(self, boading_pass_file):
        self.boarding_passes = []

        for boarding_pass in Helper.load_file(boading_pass_file):
            # The boarding pass format is just binary, so we can subsitute these characters:
            # F = 0
            # B = 1
            # L = 0
            # R = 1
            self.boarding_passes.append(int(boarding_pass.replace("F", "0").replace(
                "B", "1").replace("L", "0").replace("R", "1"), 2))
Пример #3
0
    def __init__(self, instruction_file):
        self.instructions = []
        self.fixed_loop = False

        # This logic split this horrible file into an array of dicts.
        # Since the delemeter is "double newline" instead of a single one,
        # we need to split on "\n\n".
        for line in Helper.load_file(instruction_file):
            processed_line = line.split()
            self.instructions.append(
                {"operation": processed_line[0], "arg": int(processed_line[1])})
Пример #4
0
    def __init__(self, passport_file):
        self.passport_list = []

        # This logic split this horrible file into an array of dicts.
        # Since the delemeter is "double newline" instead of a single one,
        # we need to split on "\n\n".  We also have to do some fancy string manpulation
        # because the file isn't quite in dict format.
        for line in Helper.load_file(passport_file, "\n\n"):
            line = line.replace("\n", " ")

            passport = Passport(
                {i.split(':')[0]: i.split(':')[1]
                 for i in line.split(' ')})
            if passport.has_required_fields:
                self.passport_list.append(passport)
Пример #5
0
    def __init__(self, form_file):
        self.answers = []

        # This logic split this horrible file into an array of dicts.
        # Since the delemeter is "double newline" instead of a single one,
        # we need to split on "\n\n".
        for line in Helper.load_file(form_file, "\n\n"):
            new_group = []

            # Each line in a group is it's own element.
            temp_group = line.split('\n')

            # Transforms the group into a list of sets, where each set is a person's
            # answers.
            for person in temp_group:
                new_group.append(set(person))

            self.answers.append(new_group)
Пример #6
0
    def __init__(self, baggage_file):
        self.rules_count_unique = {}
        self.rules_count_all = {}
        preprocessed_rules = Helper.load_file(baggage_file)

        # Loading dict for part 1.
        # Format: {bag1: [bag2, bag3], bag2: [bag3, bag4]}
        for rule in preprocessed_rules:

            rule = re.sub(r'(?:bag(s)?(\s)?(\.)?|\d+\s)', '', rule)
            rule = re.sub(r'\s(?:contain|,)\s', "-", rule).strip().split('-')

            bag_key = rule.pop(0)
            for item in rule:
                if item not in self.rules_count_unique:
                    self.rules_count_unique[item] = []
                self.rules_count_unique[item].append(bag_key)

        # Loading dict for part 2.
        # Format: {bag1: [{unit: bag2, quanity: 1}, {unit: bag3, quanity: 3}], \
        #   bag2: [{unit: bag4, quanity: 1}]}
        for rule in preprocessed_rules:
            rule = re.sub(r'bag(s)?(\s)?(\.)?', '', rule)
            rule = re.sub(r'\s(?:contain|,)\s', "-", rule).strip().split('-')

            bag_key = rule.pop(0)
            if bag_key not in self.rules_count_all:
                self.rules_count_all[bag_key] = []
            for item in rule:
                items = item.split(" ", 1)
                if items[0] == "no":
                    break
                self.rules_count_all[bag_key].append({
                    "quanity": int(items[0]),
                    "unit": items[1]
                })
Пример #7
0
 def __init__(self, expense_file):
     self.expense_list = Helper.load_file(expense_file, cast_int=True)
Пример #8
0
 def __init__(self, adapter_file):
     self.adapter_list = []
     self.adapter_list = Helper.load_file(adapter_file, cast_int=True)
     self.adapter_list.append(0)
     self.adapter_list.sort()
Пример #9
0
 def __init__(self, password_file):
     self.password_list = Helper.load_file(password_file)
Пример #10
0
 def __init__(self, xmas_file):
     self.xmas_data = []
     self.xmas_data = Helper.load_file(xmas_file, cast_int=True)