Esempio n. 1
0
import unittest
from aoc2021.common import puzzle_input


def part1(data):
    pass


def part2(data):
    pass


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

    def test1_part1_example1(self):
        example = self.examples[0]
        self.assertEqual(0, part1(example))

    def test2_part2_example1(self):
        example = self.examples[0]
        self.assertEqual(0, part2(example))


if __name__ == "__main__":
    # unittest.main()
    data = puzzle_input.from_arg_file()
    print("Part 1:", part1(data))
    print("Part 2:", part2(data))
Esempio n. 2
0
        least_common = 1 - int(position_sum >= len(crb) / 2)
        # print(crb)
        # print(f"col={position}, sum={position_sum}, least_common={least_common}")
        crb = list(filter(lambda b: int(b[position]) == least_common, crb))
        # print(crb)
        # print()
        position += 1
    co2_rating = int(crb[0], base=2)
    # print(co2_rating)

    return oxygen_rating * co2_rating


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

    def test1_part1_example1(self):
        example = self.examples[0].strip().split("\n")
        self.assertEqual(198, part1(example))

    def test2_part2_example1(self):
        example = self.examples[0].strip().split("\n")
        self.assertEqual(230, part2(example))


if __name__ == "__main__":
    # unittest.main()
    data = puzzle_input.from_arg_file().strip().split("\n")
    print("Part 1:", part1(data))
    print("Part 2:", part2(data))