Пример #1
0
 def main():
     pairs = load_patterns(PARENT_CHILD_REGEX, "input/d06.txt")
     counter = OrbitCounter()
     for pair in pairs:
         counter.add(pair[0], pair[1])
     print("Orbits: {0}".format(counter.get_orbits()))
     print("Transfers: {0}".format(counter.get_hops("YOU", "SAN")))
Пример #2
0
def load_signal_sets(path: str) -> List[SignalSet]:
    split_regex = re.compile('^([a-g ]+)\\| ([a-z ]+)$')
    signals = [
        SignalSet(signals=signals.split(), display=display.split())
        for signals, display in load_patterns(split_regex, path)
    ]
    return signals
Пример #3
0
 def test_load_valid(self):
     groups = load_patterns(SPLIT_REGEX, GetTestFilePath(
         "input/patterns/validPatterns.txt"))
     expected = [
         ("1", "3", "a", "abcde"),
         ("1", "3", "b", "cdefg"),
         ("2", "9", "c", "ccccccccc")
     ]
     self.assertListEqual(groups, expected)
Пример #4
0
 def main():
     passes = load_patterns(SPLIT_REGEX, "input/d02.txt")
     count = 0
     count2 = 0
     for pass_to_test in passes:
         if is_pass_valid(pass_to_test):
             count += 1
         if is_pass_valid_part_2(pass_to_test):
             count2 += 1
     print("Valid: {0}".format(count))
     print("Valid (2): {0}".format(count2))
Пример #5
0
 def test_load_invalidLine(self):
     with self.assertRaises(UnexpectedLineFormat) as context:
         load_patterns(SPLIT_REGEX,
                       GetTestFilePath("input/patterns/invalidLine"))
Пример #6
0
 def loader():
     load_patterns(
         SPLIT_REGEX,
         GetTestFilePath("input/patterns/validPatterns.txt"),
         num_results=4)