Ejemplo n.º 1
0
 def test_compute_image(self):
     # input = read_inputfile("input20.txt")
     input = read_inputfile("example20.txt")
     tiles = parse_tiles(input)
     image = compute_image(tiles)
     #print(image)
     solution = read_inputfile("example20solution.txt")
     expected = Tile(0, solution)
     self.assertIn(image, expected.get_variants())
Ejemplo n.º 2
0
    def test_part1_on_example_a(self):
        input = read_inputfile("example10a.txt")

        adapters = day10.read_numbers(input)
        print(adapters)
        (ones, threes) = day10.find_differences_in_adapter_chain(adapters)
        self.assertEqual((ones, threes), (7, 5))
Ejemplo n.º 3
0
 def test_parse_input_on_example_data(self):
     input = read_inputfile("example16a.txt")
     (rules, your_ticket, nearby_tickets) = parse_input(input)
     self.assertEqual([k for k in rules.rules.keys()],
                      ["class", "row", "seat"])
     self.assertEqual(your_ticket, [7, 1, 14])
     self.assertEqual(len(nearby_tickets), 4)
Ejemplo n.º 4
0
def main():    

    # Official input
    input = read_inputfile("input06.txt")

    print("The solution for part 1 on the official input is %d" % (part1(input)))
    print("The solution for part 2 on the official input is %d" % (part2(input)))
Ejemplo n.º 5
0
 def test_get_variants(self):
     input = read_inputfile("example20.txt")
     tiles = parse_tiles(input)
     variants = tiles[3079].get_variants()
     for tile in variants:
         print(tile)
         print()
     print("Variants: %d, %d unique." % (len(variants), len(set(variants))))
Ejemplo n.º 6
0
def main():

    input = read_inputfile("input02.txt")

    print("According to part1, the input contains %d valid passwords" %
          count_valid_passwds(input, is_valid_passwd_part1))
    print("According to part2, the input contains %d valid passwords" %
          count_valid_passwds(input, is_valid_passwd_part2))
Ejemplo n.º 7
0
    def test_find_adapter_chains_on_example_a(self):
        input = read_inputfile("example10a.txt")

        adapters = day10.read_numbers(input)
        adapters.append(0)
        adapters.append(22)
        adapters.sort()
        chains = day10.find_adapter_chains(0, adapters, [])
        self.assertEquals(len(chains), 8)
Ejemplo n.º 8
0
def main():

    input = [int(s) for s in read_inputfile("input01.txt")]

    (first, second) = find_two_entries_for_2020(input)
    print("The answer for part one is: %d" % (first * second))

    (first, second, third) = find_three_entries_for_2020(input)
    print("The answer on official data is: %d" % (first * second * third))
Ejemplo n.º 9
0
 def test_compute_your_ticket_on_example_data_a(self):
     input = read_inputfile("example16a.txt")
     (rules, your_ticket_values, nearby_tickets) = parse_input(input)
     nearby_tickets = rules.get_valid_tickets(nearby_tickets)
     # print("Valid nearby tickets: %s" % nearby_tickets)
     your_ticket = compute_our_ticket(rules, your_ticket_values,
                                      nearby_tickets)
     self.assertEqual(your_ticket["class"], 1)
     self.assertEqual(your_ticket["row"], 7)
     self.assertEqual(your_ticket["seat"], 14)
Ejemplo n.º 10
0
    def test_find_adapter_chains_on_example_b(self):
        input = read_inputfile("example10b.txt")

        adapters = day10.read_numbers(input)
        adapters.append(0)
        device = max(adapters) + 3
        adapters.append(device)
        adapters.sort()
        chains = day10.find_adapter_chains(0, adapters, [])
        self.assertEquals(len(chains), 19208)
Ejemplo n.º 11
0
    def test_part2_on_example_data_c_words(self):
        input = read_inputfile("example19c.txt")  
        (rules, patterns) = parse_rules(input)

        rules[8] = [ [ 42 ]*i for i in range(1, 10) ]
        rules[11] = [ [ 42]*i + [31]*i for i in range(1, 10) ]
        
        pattern = evaluate_rule(0, rules, patterns)

        self.assertTrue(self.can_be_verified("bbabbbbaabaabba", pattern))
        self.assertTrue(self.can_be_verified("babbbbaabbbbbabbbbbbaabaaabaaa", pattern))
Ejemplo n.º 12
0
 def test_evaluate_rules_example_b(self):
     input = read_inputfile("example19b.txt")
     (rules, patterns) = parse_rules(input)
     pattern = evaluate_rule(0, rules, patterns)
     print(pattern)
     self.assertTrue(self.can_be_verified("aaaabb", pattern))
     self.assertTrue(self.can_be_verified("aaabab", pattern))
     self.assertTrue(self.can_be_verified("abbabb", pattern))
     self.assertTrue(self.can_be_verified("abbbab", pattern))
     self.assertTrue(self.can_be_verified("aabaab", pattern))
     self.assertTrue(self.can_be_verified("aabbbb", pattern))
     self.assertTrue(self.can_be_verified("abaaab", pattern))
     self.assertTrue(self.can_be_verified("ababbb", pattern))
Ejemplo n.º 13
0
 def test_evaluate_rules_example_a(self):
     input = read_inputfile("example19a.txt")
     (rules, patterns) = parse_rules(input)
     self.assertEqual(evaluate_rule(1, rules, patterns), "a")
     self.assertEqual(evaluate_rule(2, rules, patterns), "((ab)|(ba))")
     self.assertEqual(evaluate_rule(0, rules, patterns), "((a((ab)|(ba))))")
Ejemplo n.º 14
0
 def test_parse_rules(self):
     input = read_inputfile("example19a.txt")
     (rules, patterns) = parse_rules(input)
     self.assertEqual(patterns, {1: 'a', 3: 'b'})
     self.assertEqual(rules[0], [[1, 2]])
     self.assertEqual(rules[2], [[1, 3], [3, 1]])
Ejemplo n.º 15
0
 def test_part1_on_example_data(self):
     input = read_inputfile("example04.txt")
     self.assertEqual(day04.count_passports(input, True), 2)
Ejemplo n.º 16
0
 def test_parse_passports(self):
     input = read_inputfile("example04.txt")
     self.assertEqual(len(day04.parse_passports(input)), 4)
Ejemplo n.º 17
0
 def test_part2(self):
     input = read_inputfile("example20.txt")
     self.assertEqual(part2(input), 273)
Ejemplo n.º 18
0
 def test_part2_on_example_data(self):
     input = read_inputfile("example13.txt")
     self.assertEqual(part2(input[1]), 1068781)
Ejemplo n.º 19
0
 def test_part2_on_example_data_c(self):
     input = read_inputfile("example19c.txt")
     self.assertEqual(part2(input), 12)
Ejemplo n.º 20
0
 def test_find_contiguous_block(self):
     input = read_inputfile(examplefile)
     numbers = day09.read_numbers(input)
     self.assertEqual(day09.find_contiguous_block(numbers, 127),
                      [15, 25, 47, 40])
Ejemplo n.º 21
0
 def test_find_corners(self):
     input = read_inputfile("example20.txt")
     tiles = parse_tiles(input)
     self.assertEqual(find_corners(tiles), [1951, 1171, 2971, 3079])
Ejemplo n.º 22
0
 def test_part2_on_example_data(self):
     input = read_inputfile(examplefile)
     self.assertEqual(day09.part2(input, 5), 62)
Ejemplo n.º 23
0
 def test_evaluate_rules_example_a(self):
     input = read_inputfile("example19a.txt")
     (rules, patterns) = parse_rules(input)
     self.assertEqual(evaluate_rule(1, rules, patterns), ["a"])
     self.assertEqual(evaluate_rule(2, rules, patterns), ["ab", "ba"])
     self.assertEqual(evaluate_rule(0, rules, patterns), ["aab", "aba"])
Ejemplo n.º 24
0
 def test_compute_edges_on_example_data(self):
     input = read_inputfile("example20.txt")
     tiles = parse_tiles(input)
     edgeset = tiles[3079].get_edges()
     self.assertEqual(edgeset[Orientation.UP], "#.#.#####.")
     self.assertEqual(edgeset[Orientation.LEFT], "#..##.#...")
Ejemplo n.º 25
0
 def test_parse_tiles_on_example_data(self):
     input = read_inputfile("example20.txt")
     tiles = parse_tiles(input)
     # print(tiles.keys())
     self.assertEqual(len(tiles), 9)
Ejemplo n.º 26
0
 def test_find_sea_monsters(self):
     input = read_inputfile("example20b.txt")
     sea = Tile(0, input)
     self.assertEqual(sea.find_sea_monsters(), 2)
     self.assertEqual(sea.count_hashes(), 273)
Ejemplo n.º 27
0
 def test_part1_on_example_data_b(self):
     input = read_inputfile("example19b.txt")
     self.assertEqual(part1(input), 2)
Ejemplo n.º 28
0
 def test_part1_on_example(self):
     input = read_inputfile("example20.txt")
     self.assertEqual(part1(input), 20899048083289)
Ejemplo n.º 29
0
 def test_count_common_edges(self):
     input = read_inputfile("example20.txt")
     tiles = parse_tiles(input)
     self.assertEqual(tiles[2971].count_comon_edges(tiles[1489]), 1)
Ejemplo n.º 30
0
 def test_evaluate_rules_example_b(self):
     input = read_inputfile("example19b.txt")
     (rules, patterns) = parse_rules(input)
     self.assertEqual(evaluate_rule(0, rules, patterns), 
         ["aaaabb", "aaabab", "abbabb", "abbbab", "aabaab", "aabbbb", "abaaab", "ababbb"])