Ejemplo n.º 1
0
 def test2_part2_example1(self):
     self.assertEqual(175594, Solution().part2("0,3,6"))
Ejemplo n.º 2
0
            spoken[number].append(turn)

    return number


class Solution(Solution):
    def part1(self, input):
        input = parse_input(input)
        return van_eck_sequence(input, 2020)

    def part2(self, input):
        input = parse_input(input)
        return van_eck_sequence(input, 30000000)


class Test(TimedTestCase):
    examples = puzzle_input.from_examples(__file__)  # list of stripped str

    def test1_part1_example1(self):
        self.assertEqual(436, Solution().part1("0,3,6"))

    def test2_part2_example1(self):
        self.assertEqual(175594, Solution().part2("0,3,6"))


if __name__ == "__main__":
    # unittest.main()
    input = puzzle_input.from_arg_file()
    print("Part 1:", Solution().part1(input))
    print("Part 2:", Solution().part2(input))
Ejemplo n.º 3
0
 def test1_part1_example1(self):
     self.assertEqual(436, Solution().part1("0,3,6"))
Ejemplo n.º 4
0
 def test2_part2_example2(self):
     self.assertEqual(208, Solution().part2(self.examples[1]))
Ejemplo n.º 5
0
 def test1_part1_example1(self):
     self.assertEqual(165, Solution().part1(self.examples[0]))
Ejemplo n.º 6
0
                    addresses = []
                    for combination in range(2**len(positions)):
                        floating_mask = list("{0:b}".format(combination).zfill(
                            len(positions)))
                        address_bits_copy = address_bits.copy()
                        for i, bit in enumerate(floating_mask):
                            address_bits_copy[positions[i]] = bit
                        addresses.append(int("".join(address_bits_copy), 2))
                    for address in addresses:
                        memory[address] = value
        return sum(memory.values())


class Test(TimedTestCase):
    examples = puzzle_input.from_examples(__file__)  # list of stripped str

    def test1_part1_example1(self):
        self.assertEqual(165, Solution().part1(self.examples[0]))

    def test2_part2_example2(self):
        self.assertEqual(208, Solution().part2(self.examples[1]))


if __name__ == "__main__":
    # unittest.main()
    input = puzzle_input.from_arg_file()

    solution = Solution()
    print("Part 1:", solution.part1(input))
    print("Part 2:", solution.part2(input))
Ejemplo n.º 7
0
 def test2_part2_example1(self):
     self.assertEqual(3417, Solution().part2(self.examples[1]))
Ejemplo n.º 8
0
 def test2_part2_example1(self):
     self.assertEqual(286, Solution().part2(self.examples[0]))