diff --git a/tests/y_2019/test_2019_common.py b/tests/y_2019/test_2019_common.py deleted file mode 100644 index 693a61b..0000000 --- a/tests/y_2019/test_2019_common.py +++ /dev/null @@ -1,24 +0,0 @@ -import contextlib -from unittest.mock import patch - -from y_2019.common import load_input, main - - -def test_load_input_string(): - with patch("y_2019.common.open") as open_patch: - open_patch().__enter__().read = lambda: "hello" - assert load_input(0) == ["hello"] - - -def test_load_input_multiline(): - with patch("y_2019.common.open") as open_patch: - open_patch().__enter__().read = lambda: "hello\nworld\n" - assert load_input(0) == ["hello", "world"] - - -def test_main(): - with contextlib.ExitStack() as patches: - patches.enter_context(patch("y_2019.common.argparse")) - patches.enter_context(patch("y_2019.common.open")) - patches.enter_context(patch("y_2019.common.importlib")) - assert main() is None diff --git a/tests/y_2019/test_2019_day1.py b/tests/y_2019/test_2019_day1.py deleted file mode 100644 index b0d693c..0000000 --- a/tests/y_2019/test_2019_day1.py +++ /dev/null @@ -1,43 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2019.day1 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - day._input_data = [ - "143843", - "144558", - "116244", - ] - day._preprocess_input() - assert day._Day__mass_list == [143843, 144558, 116244] - - day._input_data = [] - day._preprocess_input() - assert day._Day__mass_list == [] - - -def test_calculate_1(): - day._Day__mass_list = [12] - assert day._calculate_1() == 2 - - -def test_calculate_2(): - day._Day__mass_list = [100756] - assert day._calculate_2() == 50346 - - -def test_fuel_from_mass(): - assert Day.fuel_from_mass(12) == 2 - assert Day.fuel_from_mass(14) == 2 - assert Day.fuel_from_mass(1969) == 654 - assert Day.fuel_from_mass(100756) == 33583 - - -def test_total_fuel_from_mass(): - assert Day.total_fuel_from_mass(14) == 2 - assert Day.total_fuel_from_mass(1969) == 966 - assert Day.total_fuel_from_mass(100756) == 50346 diff --git a/tests/y_2020/test_2020_common.py b/tests/y_2020/test_2020_common.py deleted file mode 100644 index 43d2155..0000000 --- a/tests/y_2020/test_2020_common.py +++ /dev/null @@ -1,46 +0,0 @@ -import contextlib -from unittest.mock import patch - -from y_2020.common import AoCDay, load_input, main - - -def test_load_input_string(): - with patch("y_2020.common.open") as open_patch: - open_patch().__enter__().read = lambda: "hello" - assert load_input(0) == ["hello"] - - -def test_load_input_multiline(): - with patch("y_2020.common.open") as open_patch: - open_patch().__enter__().read = lambda: "hello\nworld\n" - assert load_input(0) == ["hello", "world"] - - -def test_main(): - with contextlib.ExitStack() as patches: - patches.enter_context(patch("y_2020.common.argparse")) - patches.enter_context(patch("y_2020.common.open")) - patches.enter_context(patch("y_2020.common.importlib")) - assert main() is None - - -class MockAoCDay(AoCDay): - def __init__(self): - super().__init__(0) - - def _calculate_1(self): - pass - - def _calculate_2(self): - pass - - def _preprocess_input(self): - pass - - -def test_AoCDay(): - print() - with patch("y_2020.common.open") as open_patch: - open_patch().__enter__().read = lambda: "hello\nworld\n" - mock_aoc_day = MockAoCDay() - assert mock_aoc_day.solve() is None diff --git a/tests/y_2020/test_2020_day1.py b/tests/y_2020/test_2020_day1.py deleted file mode 100644 index 7458f2c..0000000 --- a/tests/y_2020/test_2020_day1.py +++ /dev/null @@ -1,30 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day1 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - day._input_data = ["1721", "979", "366", "299", "675", "1456"] - day._preprocess_input() - assert day._Day__input_data == [1721, 979, 366, 299, 675, 1456] - - day._input_data = [] - day._preprocess_input() - assert day._Day__input_data == [] - - -def test_calculate_1(): - day._Day__input_data = [1721, 979, 366, 299, 675, 1456] - assert day._calculate_1() == 514579 - day._Day__input_data = [] - assert day._calculate_1() == 0 - - -def test_calculate_2(): - day._Day__input_data = [1721, 979, 366, 299, 675, 1456] - assert day._calculate_2() == 241861950 - day._Day__input_data = [] - assert day._calculate_2() == 0 diff --git a/tests/y_2020/test_2020_day10.py b/tests/y_2020/test_2020_day10.py deleted file mode 100644 index 743a934..0000000 --- a/tests/y_2020/test_2020_day10.py +++ /dev/null @@ -1,93 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day10 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [16, 10, 15, 5, 1, 11, 7, 19, 6, 12, 4] - day._preprocess_input() - assert day._Day__input == [16, 10, 15, 5, 1, 11, 7, 19, 6, 12, 4] - - -def test_calculate_1(): - print() - day._Day__input = [16, 10, 15, 5, 1, 11, 7, 19, 6, 12, 4] - assert day._calculate_1() == 7 * 5 - day._Day__input = [ - 28, - 33, - 18, - 42, - 31, - 14, - 46, - 20, - 48, - 47, - 24, - 23, - 49, - 45, - 19, - 38, - 39, - 11, - 1, - 32, - 25, - 35, - 8, - 17, - 7, - 9, - 4, - 2, - 34, - 10, - 3, - ] - assert day._calculate_1() == 22 * 10 - - -def test_calculate_2(): - print() - day._Day__input = [16, 10, 15, 5, 1, 11, 7, 19, 6, 12, 4] - assert day._calculate_2() == 8 - day._Day__input = [ - 28, - 33, - 18, - 42, - 31, - 14, - 46, - 20, - 48, - 47, - 24, - 23, - 49, - 45, - 19, - 38, - 39, - 11, - 1, - 32, - 25, - 35, - 8, - 17, - 7, - 9, - 4, - 2, - 34, - 10, - 3, - ] - assert day._calculate_2() == 19208 diff --git a/tests/y_2020/test_2020_day11.py b/tests/y_2020/test_2020_day11.py deleted file mode 100644 index 1e3ef5f..0000000 --- a/tests/y_2020/test_2020_day11.py +++ /dev/null @@ -1,185 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day11 import Day - -with patch("builtins.open", mock_open(read_data="\n")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [ - "L.LL.LL.LL", - "LLLLLLL.LL", - "L.L.L..L..", - "LLLL.LL.LL", - "L.LL.LL.LL", - "L.LLLLL.LL", - "..L.L.....", - "LLLLLLLLLL", - "L.LLLLLL.L", - "L.LLLLL.LL", - ] - day._preprocess_input() - assert day._Day__input == [ - "L.LL.LL.LL", - "LLLLLLL.LL", - "L.L.L..L..", - "LLLL.LL.LL", - "L.LL.LL.LL", - "L.LLLLL.LL", - "..L.L.....", - "LLLLLLLLLL", - "L.LLLLLL.L", - "L.LLLLL.LL", - ] - - -def test__iterate_adjacent_1(): - print() - day._Day__input = [ - "L.LL.LL.LL", - "LLLLLLL.LL", - "L.L.L..L..", - "LLLL.LL.LL", - "L.LL.LL.LL", - "L.LLLLL.LL", - "..L.L.....", - "LLLLLLLLLL", - "L.LLLLLL.L", - "L.LLLLL.LL", - ] - day._Day__iterate_adjacent() - assert day._Day__input == [ - "#.##.##.##", - "#######.##", - "#.#.#..#..", - "####.##.##", - "#.##.##.##", - "#.#####.##", - "..#.#.....", - "##########", - "#.######.#", - "#.#####.##", - ] - - -def test__iterate_adjacent_2(): - print() - day._Day__input = [ - "#.##.##.##", - "#######.##", - "#.#.#..#..", - "####.##.##", - "#.##.##.##", - "#.#####.##", - "..#.#.....", - "##########", - "#.######.#", - "#.#####.##", - ] - day._Day__iterate_adjacent() - assert day._Day__input == [ - "#.LL.L#.##", - "#LLLLLL.L#", - "L.L.L..L..", - "#LLL.LL.L#", - "#.LL.LL.LL", - "#.LLLL#.##", - "..L.L.....", - "#LLLLLLLL#", - "#.LLLLLL.L", - "#.#LLLL.##", - ] - - -def test_calculate_1(): - print() - day._Day__input = [ - "L.LL.LL.LL", - "LLLLLLL.LL", - "L.L.L..L..", - "LLLL.LL.LL", - "L.LL.LL.LL", - "L.LLLLL.LL", - "..L.L.....", - "LLLLLLLLLL", - "L.LLLLLL.L", - "L.LLLLL.LL", - ] - assert day._calculate_1() == 37 - - -def test__iterate_visible_1(): - print() - day._Day__input = [ - "L.LL.LL.LL", - "LLLLLLL.LL", - "L.L.L..L..", - "LLLL.LL.LL", - "L.LL.LL.LL", - "L.LLLLL.LL", - "..L.L.....", - "LLLLLLLLLL", - "L.LLLLLL.L", - "L.LLLLL.LL", - ] - day._Day__iterate_visible() - assert day._Day__input == [ - "#.##.##.##", - "#######.##", - "#.#.#..#..", - "####.##.##", - "#.##.##.##", - "#.#####.##", - "..#.#.....", - "##########", - "#.######.#", - "#.#####.##", - ] - - -def test__Day__iterate_visible_2(): - print() - day._Day__input = [ - "#.##.##.##", - "#######.##", - "#.#.#..#..", - "####.##.##", - "#.##.##.##", - "#.#####.##", - "..#.#.....", - "##########", - "#.######.#", - "#.#####.##", - ] - day._Day__iterate_visible() - assert day._Day__input == [ - "#.LL.LL.L#", - "#LLLLLL.LL", - "L.L.L..L..", - "LLLL.LL.LL", - "L.LL.LL.LL", - "L.LLLLL.LL", - "..L.L.....", - "LLLLLLLLL#", - "#.LLLLLL.L", - "#.LLLLL.L#", - ] - - -def test_calculate_2(): - print() - day._Day__input = [ - "L.LL.LL.LL", - "LLLLLLL.LL", - "L.L.L..L..", - "LLLL.LL.LL", - "L.LL.LL.LL", - "L.LLLLL.LL", - "..L.L.....", - "LLLLLLLLLL", - "L.LLLLLL.L", - "L.LLLLL.LL", - ] - assert day._calculate_2() == 26 diff --git a/tests/y_2020/test_2020_day12.py b/tests/y_2020/test_2020_day12.py deleted file mode 100644 index 02ab658..0000000 --- a/tests/y_2020/test_2020_day12.py +++ /dev/null @@ -1,63 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day12 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [ - "F10", - "N3", - "F7", - "R90", - "F11", - ] - - day._preprocess_input() - assert day._Day__input == [ - ("F", 10), - ("N", 3), - ("F", 7), - ("R", 90), - ("F", 11), - ] - - -def test_calculate_1(): - print() - day._Day__input = [ - ("F", 10), - ("N", 3), - ("F", 7), - ("R", 90), - ("F", 11), - ] - assert day._calculate_1() == 25 - - -def test_calculate_2(): - print() - day._Day__input = [ - ("F", 10), - ("N", 3), - ("F", 7), - ("R", 90), - ("F", 11), - ] - assert day._calculate_2() == 286 - - -def test_calculate_2_bis(): - print() - day._Day__input = [ - ("F", 10), - ("N", 3), - ("F", 7), - ("R", 90), - ("F", 11), - ("L", 90), - ] - assert day._calculate_2() == 286 diff --git a/tests/y_2020/test_2020_day13.py b/tests/y_2020/test_2020_day13.py deleted file mode 100644 index b1aaa45..0000000 --- a/tests/y_2020/test_2020_day13.py +++ /dev/null @@ -1,79 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day13 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [] - day._preprocess_input() - assert day._Day__input == [] - - -def test_calculate_1(): - print() - day._Day__input = ["939", "7,13,x,x,59,x,31,19"] - assert day._calculate_1() == 295 - - -def test_calculate_2_basic(): - print() - day._Day__input = ["939", "7,13"] - assert day._calculate_2() == 77 - - -def test_calculate_2_basic_1(): - print() - day._Day__input = ["939", "7,13,x,x,59"] - assert day._calculate_2() == 350 - - -def test_calculate_2_basic_1_bis(): - print() - day._Day__input = ["939", "17,x,13,19"] - assert day._calculate_2() == 3417 - - -def test_calculate_2_basic_2(): - print() - day._Day__input = ["939", "7,13,x,x,59,x,31"] - assert day._calculate_2() == 70147 - - -def test_calculate_2(): - print() - day._Day__input = ["939", "7,13,x,x,59,x,31,19"] - assert day._calculate_2() == 1068781 - - -def test_calculate_2_2(): - print() - day._Day__input = ["", "17,x,13,19"] - assert day._calculate_2() == 3417 - - -def test_calculate_2_3(): - print() - day._Day__input = ["", "67,7,59,61"] - assert day._calculate_2() == 754018 - - -def test_calculate_2_4(): - print() - day._Day__input = ["", "67,x,7,59,61"] - assert day._calculate_2() == 779210 - - -def test_calculate_2_5(): - print() - day._Day__input = ["", "67,7,x,59,61"] - assert day._calculate_2() == 1261476 - - -def test_calculate_2_6(): - print() - day._Day__input = ["", "1789,37,47,1889"] - assert day._calculate_2() == 1_202_161_486 diff --git a/tests/y_2020/test_2020_day14.py b/tests/y_2020/test_2020_day14.py deleted file mode 100644 index 4f87eb1..0000000 --- a/tests/y_2020/test_2020_day14.py +++ /dev/null @@ -1,56 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day14 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [ - "mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X", - "mem[8] = 11", - "mem[7] = 101", - "mem[8] = 0", - ] - day._preprocess_input() - assert day._Day__input == [ - "mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X", - "mem[8] = 11", - "mem[7] = 101", - "mem[8] = 0", - ] - - -def test_calculate_1(): - print() - day._Day__input = [ - "mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X", - "mem[8] = 11", - "mem[7] = 101", - "mem[8] = 0", - ] - assert day._calculate_1() == 165 - - -def test_calculate_2(): - print() - day._Day__input = [ - "mask = 000000000000000000000000000000X1001X", - "mem[42] = 100", - "mask = 00000000000000000000000000000000X0XX", - "mem[26] = 1", - ] - assert day._calculate_2() == 208 - - -def test_calculate_2_short(): - print() - day._Day__input = [ - "mask = 0X1001X", - "mem[42] = 100", - "mask = 000X0XX", - "mem[26] = 1", - ] - assert day._calculate_2() == 208 diff --git a/tests/y_2020/test_2020_day15.py b/tests/y_2020/test_2020_day15.py deleted file mode 100644 index 21a96da..0000000 --- a/tests/y_2020/test_2020_day15.py +++ /dev/null @@ -1,27 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day15 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = ["0,3,6"] - day._preprocess_input() - assert day._Day__input == ["0,3,6"] - - -def test_calculate_1(): - print() - return # sourcery skip: remove-unreachable-code - day._Day__input = ["0,3,6"] - assert day._calculate_1() == 436 - - -def test_calculate_2(): - print() - return # sourcery skip: remove-unreachable-code - day._Day__input = ["0,3,6"] - assert day._calculate_2() == 175594 diff --git a/tests/y_2020/test_2020_day16.py b/tests/y_2020/test_2020_day16.py deleted file mode 100644 index d3dedd9..0000000 --- a/tests/y_2020/test_2020_day16.py +++ /dev/null @@ -1,50 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day16 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [] - day._preprocess_input() - assert day._Day__input == [] - - -def test_calculate_1(): - print() - day._Day__input = [ - "class: 1-3 or 5-7", - "row: 6-11 or 33-44", - "seat: 13-40 or 45-50", - "", - "your ticket:", - "7,1,14", - "", - "nearby tickets:", - "7,3,47", - "40,4,50", - "55,2,20", - "38,6,12", - ] - assert day._calculate_1() == 71 - - -def test_calculate_2(): - print() - day._Day__input = [ - "class: 0-1 or 4-19", - "row: 0-5 or 8-19", - "seat: 0-13 or 16-19", - "", - "your ticket:", - "11,12,13", - "", - "nearby tickets:", - "3,9,18", - "15,1,5", - "5,14,9", - ] - assert day._calculate_2() == 1 diff --git a/tests/y_2020/test_2020_day17.py b/tests/y_2020/test_2020_day17.py deleted file mode 100644 index 388cf96..0000000 --- a/tests/y_2020/test_2020_day17.py +++ /dev/null @@ -1,499 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day17 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [ - ".#.", - "..#", - "###", - ] - day._preprocess_input() - assert day._Day__3dworld == [ - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", "#", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", "#", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", "#", "#", "#", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - ] - - -def test_iteration(): - print() - return # sourcery skip: remove-unreachable-code - day._input_data = [ - ".#.", - "..#", - "###", - ] - day._preprocess_input() - day._Day__iteration3d() - # sourcery skip: remove-assert-true, remove-redundant-boolean - assert True or day._Day__3dworld == [ - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - [ - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - [".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."], - ], - ] - - -def test_calculate_1(): - print() - return # sourcery skip: remove-unreachable-code - day._input_data = [ - ".#.", - "..#", - "###", - ] - day._preprocess_input() - assert day._calculate_1() == 112 - - -def test_calculate_2(): - print() - return # sourcery skip: remove-unreachable-code - day._input_data = [ - ".#.", - "..#", - "###", - ] - day._preprocess_input() - assert day._calculate_2() == 848 diff --git a/tests/y_2020/test_2020_day18.py b/tests/y_2020/test_2020_day18.py deleted file mode 100644 index ed529f4..0000000 --- a/tests/y_2020/test_2020_day18.py +++ /dev/null @@ -1,55 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day18 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [] - day._preprocess_input() - assert day._Day__input == [] - - -def test_calculate_1(): - print() - day._Day__input = ["1 + 2 * 3 + 4 * 5 + 6"] - assert day._calculate_1() == 71 - day._Day__input = ["1 + (2 * 3) + (4 * (5 + 6))"] - assert day._calculate_1() == 51 - day._Day__input = ["2 * 3 + (4 * 5)"] - assert day._calculate_1() == 26 - day._Day__input = ["5 + (8 * 3 + 9 + 3 * 4 * 3)"] - assert day._calculate_1() == 437 - day._Day__input = ["5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"] - assert day._calculate_1() == 12240 - day._Day__input = ["((2 + 3 * 4) * (5 + 6 * 7 + 8) + 9) + 4 + 5 * 6"] - assert day._calculate_1() == 10308 - day._Day__input = ["((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2"] - assert day._calculate_1() == 13632 - - -# ((5*4)*(11*15)+9)+4+5*6 -# (20*165+9)+4+5*6 -# (20*174)+4+5*6 -# 3480+4+5*6 -# 3489*6 -# 20934 -def test_calculate_2(): - print() - day._Day__input = ["1 + 2 * 3 + 4 * 5 + 6"] - assert day._calculate_2() == 231 - day._Day__input = ["1 + (2 * 3) + (4 * (5 + 6))"] - assert day._calculate_2() == 51 - day._Day__input = ["2 * 3 + (4 * 5)"] - assert day._calculate_2() == 46 - day._Day__input = ["5 + (8 * 3 + 9 + 3 * 4 * 3)"] - assert day._calculate_2() == 1445 - day._Day__input = ["5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"] - assert day._calculate_2() == 669060 - day._Day__input = ["((2 + 3 * 4) * (5 + 6 * 7 + 8) + 9) + 4 + 5 * 6"] - assert day._calculate_2() == 20934 - day._Day__input = ["((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2"] - assert day._calculate_2() == 23340 diff --git a/tests/y_2020/test_2020_day19.py b/tests/y_2020/test_2020_day19.py deleted file mode 100644 index 34ba9c9..0000000 --- a/tests/y_2020/test_2020_day19.py +++ /dev/null @@ -1,158 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day19 import Day - -with patch("builtins.open", mock_open(read_data="0: 0")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = ["0: 1 | 2", '1: "a"', '2: "b"', "", "a"] - day._preprocess_input() - assert day._Day__rules == {0: ["1", "2"], 1: ["a"], 2: ["b"]} - assert day._Day__messages == ["a"] - - -def test_calculate_1(): - print() - day._input_data = [ - "0: 4 1 5", - "1: 2 3", - "2: 4 4", - "3: 4 5", - '4: "a"', - '5: "b"', - "", - "aaaabb", - "aaaabb", - ] - day._preprocess_input() - assert day._calculate_1() == 2 - - day._input_data = [ - "0: 4 1 5", - "1: 2 3 | 3 2", - "2: 4 4 | 5 5", - "3: 4 5 | 5 4", - '4: "a"', - '5: "b"', - "", - "ababbb", - "bababa", - "abbbab", - "aaabbb", - "aaaabbb", - ] - day._preprocess_input() - assert day._calculate_1() == 2 - - -def test_calculate_2_logic1(): - print() - day._input_data = [ - "42: 9 14 | 10 1", - "9: 14 27 | 1 26", - "10: 23 14 | 28 1", - '1: "a"', - "11: 42 31", - "5: 1 14 | 15 1", - "19: 14 1 | 14 14", - "12: 24 14 | 19 1", - "16: 15 1 | 14 14", - "31: 14 17 | 1 13", - "6: 14 14 | 1 14", - "2: 1 24 | 14 4", - "0: 8 11", - "13: 14 3 | 1 12", - "15: 1 | 14", - "17: 14 2 | 1 7", - "23: 25 1 | 22 14", - "28: 16 1", - "4: 1 1", - "20: 14 14 | 1 15", - "3: 5 14 | 16 1", - "27: 1 6 | 14 18", - '14: "b"', - "21: 14 1 | 1 14", - "25: 1 1 | 1 14", - "22: 14 14", - "8: 42", - "26: 14 22 | 1 20", - "18: 15 15", - "7: 14 5 | 1 21", - "24: 14 1", - "", - "abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa", - "bbabbbbaabaabba", - "babbbbaabbbbbabbbbbbaabaaabaaa", - "aaabbbbbbaaaabaababaabababbabaaabbababababaaa", - "bbbbbbbaaaabbbbaaabbabaaa", - "bbbababbbbaaaaaaaabbababaaababaabab", - "ababaaaaaabaaab", - "ababaaaaabbbaba", - "baabbaaaabbaaaababbaababb", - "abbbbabbbbaaaababbbbbbaaaababb", - "aaaaabbaabaaaaababaa", - "aaaabbaaaabbaaa", - "aaaabbaabbaaaaaaabbbabbbaaabbaabaaa", - "babaaabbbaaabaababbaabababaaab", - "aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba", - ] - day._preprocess_input() - assert day._calculate_1() == 3 - - -def test_calculate_2(): - print() - day._input_data = [ - "42: 9 14 | 10 1", - "9: 14 27 | 1 26", - "10: 23 14 | 28 1", - '1: "a"', - "11: 42 31", - "5: 1 14 | 15 1", - "19: 14 1 | 14 14", - "12: 24 14 | 19 1", - "16: 15 1 | 14 14", - "31: 14 17 | 1 13", - "6: 14 14 | 1 14", - "2: 1 24 | 14 4", - "0: 8 11", - "13: 14 3 | 1 12", - "15: 1 | 14", - "17: 14 2 | 1 7", - "23: 25 1 | 22 14", - "28: 16 1", - "4: 1 1", - "20: 14 14 | 1 15", - "3: 5 14 | 16 1", - "27: 1 6 | 14 18", - '14: "b"', - "21: 14 1 | 1 14", - "25: 1 1 | 1 14", - "22: 14 14", - "8: 42", - "26: 14 22 | 1 20", - "18: 15 15", - "7: 14 5 | 1 21", - "24: 14 1", - "", - "abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa", - "bbabbbbaabaabba", - "babbbbaabbbbbabbbbbbaabaaabaaa", - "aaabbbbbbaaaabaababaabababbabaaabbababababaaa", - "bbbbbbbaaaabbbbaaabbabaaa", - "bbbababbbbaaaaaaaabbababaaababaabab", - "ababaaaaaabaaab", - "ababaaaaabbbaba", - "baabbaaaabbaaaababbaababb", - "abbbbabbbbaaaababbbbbbaaaababb", - "aaaaabbaabaaaaababaa", - "aaaabbaaaabbaaa", - "aaaabbaabbaaaaaaabbbabbbaaabbaabaaa", - "babaaabbbaaabaababbaabababaaab", - "aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba", - ] - day._preprocess_input() - assert day._calculate_2() == 12 diff --git a/tests/y_2020/test_2020_day2.py b/tests/y_2020/test_2020_day2.py deleted file mode 100644 index 3c63d99..0000000 --- a/tests/y_2020/test_2020_day2.py +++ /dev/null @@ -1,38 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day2 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - day._input_data = [ - "1-3 a: abcde", - "1-3 b: cdefg", - "2-9 c: ccccccccc", - ] - day._preprocess_input() - assert day._Day__password_list == [ - (1, 3, "a", "abcde"), - (1, 3, "b", "cdefg"), - (2, 9, "c", "ccccccccc"), - ] - - -def test_calculate_1(): - day._Day__password_list = [ - (1, 3, "a", "abcde"), - (1, 3, "b", "cdefg"), - (2, 9, "c", "ccccccccc"), - ] - assert day._calculate_1() == 2 - - -def test_calculate_2(): - day._Day__password_list = [ - (1, 3, "a", "abcde"), - (1, 3, "b", "cdefg"), - (2, 9, "c", "ccccccccc"), - ] - assert day._calculate_2() == 1 diff --git a/tests/y_2020/test_2020_day3.py b/tests/y_2020/test_2020_day3.py deleted file mode 100644 index 382ce46..0000000 --- a/tests/y_2020/test_2020_day3.py +++ /dev/null @@ -1,40 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day3 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test_calculate_1(): - day._input_data = [ - "..##.......", - "#...#...#..", - ".#....#..#.", - "..#.#...#.#", - ".#...##..#.", - "..#.##.....", - ".#.#.#....#", - ".#........#", - "#.##...#...", - "#...##....#", - ".#..#...#.#", - ] - assert day._calculate_1() == 7 - - -def test_calculate_2(): - day._input_data = [ - "..##.......", - "#...#...#..", - ".#....#..#.", - "..#.#...#.#", - ".#...##..#.", - "..#.##.....", - ".#.#.#....#", - ".#........#", - "#.##...#...", - "#...##....#", - ".#..#...#.#", - ] - assert day._calculate_2() == 336 diff --git a/tests/y_2020/test_2020_day4.py b/tests/y_2020/test_2020_day4.py deleted file mode 100644 index 6e8f99c..0000000 --- a/tests/y_2020/test_2020_day4.py +++ /dev/null @@ -1,206 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day4 import Day, collapse_strings - -with patch("builtins.open", mock_open(read_data=":")): - day = Day() - - -def test_collapse_strings(): - assert collapse_strings(["x", "", "y1", "y2"]) == ["x", "y1 y2"] - assert collapse_strings(["x", "y", "", "z"]) == ["x y", "z"] - assert collapse_strings( - [ - "ecl:gry pid:860033327 eyr:2020 hcl:#fffffd", - "byr:1937 iyr:2017 cid:147 hgt:183cm", - "", - "iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884", - "hcl:#cfa07d byr:1929", - ] - ) == [ - "ecl:gry pid:860033327 eyr:2020 hcl:#fffffd " - "byr:1937 iyr:2017 cid:147 hgt:183cm", - "iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884 hcl:#cfa07d byr:1929", - ] - - -def test_preprocess_input(): - day._input_data = [ - "ecl:gry pid:860033327 eyr:2020 hcl:#fffffd", - "byr:1937 iyr:2017 cid:147 hgt:183cm", - "", - "iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884", - "hcl:#cfa07d byr:1929", - ] - day._preprocess_input() - assert day._Day__passport_list == [ - { - "ecl": "gry", - "pid": "860033327", - "eyr": "2020", - "hcl": "#fffffd", - "byr": "1937", - "iyr": "2017", - "cid": "147", - "hgt": "183cm", - }, - { - "iyr": "2013", - "ecl": "amb", - "cid": "350", - "eyr": "2023", - "pid": "028048884", - "hcl": "#cfa07d", - "byr": "1929", - }, - ] - - -def test_calculate_1(): - day._Day__passport_list = [ - { - "byr": "1937", - "cid": "147", - "ecl": "gry", - "eyr": "2020", - "hcl": "#fffffd", - "hgt": "183cm", - "iyr": "2017", - "pid": "860033327", - }, - { - "byr": "1929", - "cid": "350", - "ecl": "amb", - "eyr": "2023", - "hcl": "#cfa07d", - "iyr": "2013", - "pid": "028048884", - }, - { - "byr": "1931", - "ecl": "brn", - "eyr": "2024", - "hcl": "#ae17e1", - "hgt": "179cm", - "iyr": "2013", - "pid": "760753108", - }, - { - "ecl": "brn", - "eyr": "2025", - "hcl": "#cfa07d", - "hgt": "59in", - "iyr": "2011", - "pid": "166559648", - }, - ] - assert day._calculate_1() == 2 - - -def test_calculate_2(): - day._Day__passport_list = [ - { - "byr": "1926", - "cid": "100", - "ecl": "amb", - "eyr": "1972", - "hcl": "#18171d", - "hgt": "170", - "iyr": "2018", - "pid": "186cm", - }, - { - "byr": "1946", - "ecl": "grn", - "eyr": "1967", - "hcl": "#602927", - "hgt": "170cm", - "iyr": "2019", - "pid": "012533040", - }, - { - "byr": "1992", - "cid": "277", - "ecl": "brn", - "eyr": "2020", - "hcl": "dab227", - "hgt": "182cm", - "iyr": "2012", - "pid": "021572410", - }, - { - "byr": "2007", - "ecl": "zzz", - "eyr": "2038", - "hcl": "74454a", - "hgt": "59cm", - "iyr": "2023", - "pid": "3556412378", - }, - ] - assert day._calculate_2() == 0 - - day._Day__passport_list = [ - { - "byr": "1980", - "ecl": "grn", - "eyr": "2030", - "hcl": "#623a2f", - "hgt": "74in", - "iyr": "2012", - "pid": "087499704", - }, - { - "byr": "1989", - "cid": "129", - "ecl": "blu", - "eyr": "2029", - "hcl": "#a97842", - "hgt": "165cm", - "iyr": "2014", - "pid": "896056539", - }, - { - "byr": "2001", - "cid": "88", - "ecl": "hzl", - "eyr": "2022", - "hcl": "#888785", - "hgt": "164cm", - "iyr": "2015", - "pid": "545766238", - }, - { - "byr": "1944", - "ecl": "blu", - "eyr": "2021", - "hcl": "#b6652a", - "hgt": "158cm", - "iyr": "2010", - "pid": "093154719", - }, - ] - assert day._calculate_2() == 4 - - -def test_validate_element(): - assert day._Day__validate_element("byr", "2002") is True - assert day._Day__validate_element("byr", "2003") is False - - assert day._Day__validate_element("hgt", "60in") is True - assert day._Day__validate_element("hgt", "190cm") is True - - assert day._Day__validate_element("hgt", "190in") is False - assert day._Day__validate_element("hgt", "190") is False - - assert day._Day__validate_element("hcl", "#123abc") is True - assert day._Day__validate_element("hcl", "#123abz") is False - assert day._Day__validate_element("hcl", "123abc") is False - assert day._Day__validate_element("hcl", "dab227") is False - - assert day._Day__validate_element("ecl", "brn") is True - assert day._Day__validate_element("ecl", "wat") is False - - assert day._Day__validate_element("pid", "000000001") is True - assert day._Day__validate_element("pid", "0123456789") is False diff --git a/tests/y_2020/test_2020_day5.py b/tests/y_2020/test_2020_day5.py deleted file mode 100644 index f7953a0..0000000 --- a/tests/y_2020/test_2020_day5.py +++ /dev/null @@ -1,34 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day5 import Day - -with patch("builtins.open", mock_open(read_data=":")): - day = Day() - - -def test_preprocess_input(): - day._input_data = ["FBFBBFFRLR"] - day._preprocess_input() - assert day._Day__decoded_seats == [357] - - day._input_data = ["BFFFBBFRRR"] - day._preprocess_input() - assert day._Day__decoded_seats == [567] - - day._input_data = ["FFFBBBFRRR"] - day._preprocess_input() - - assert day._Day__decoded_seats == [119] - day._input_data = ["BBFFBBFRLL"] - day._preprocess_input() - assert day._Day__decoded_seats == [820] - - -def test_calculate_1(): - day._Day__decoded_seats = [357, 567, 119] - assert day._calculate_1() == 567 - - -def test_calculate_2(): - day._Day__decoded_seats = [18, 19, 21, 22] - assert day._calculate_2() == 20 diff --git a/tests/y_2020/test_2020_day6.py b/tests/y_2020/test_2020_day6.py deleted file mode 100644 index b9f07ac..0000000 --- a/tests/y_2020/test_2020_day6.py +++ /dev/null @@ -1,56 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day6 import Counter, Day, UserGroup - -with patch("builtins.open", mock_open(read_data=":")): - day = Day() - - -def test__preprocess_input(): - day._input_data = [ - "abc", - "", - "a", - "b", - "c", - "", - "ab", - "ac", - "", - "a", - "a", - "a", - "a", - "", - "b", - ] - day._preprocess_input() - assert day._Day__user_groups == [ - UserGroup(answers=Counter({"a": 1, "b": 1, "c": 1}), size=1), - UserGroup(answers=Counter({"a": 1, "b": 1, "c": 1}), size=3), - UserGroup(answers=Counter({"a": 2, "b": 1, "c": 1}), size=2), - UserGroup(answers=Counter({"a": 4}), size=4), - UserGroup(answers=Counter({"b": 1}), size=1), - ] - - -def test_calculate_1(): - day._Day__user_groups = [ - UserGroup(answers=Counter({"a": 1, "b": 1, "c": 1}), size=1), - UserGroup(answers=Counter({"a": 1, "b": 1, "c": 1}), size=3), - UserGroup(answers=Counter({"a": 2, "b": 1, "c": 1}), size=2), - UserGroup(answers=Counter({"a": 4}), size=4), - UserGroup(answers=Counter({"b": 1}), size=1), - ] - assert day._calculate_1() == 11 - - -def test_calculate_2(): - day._Day__user_groups = [ - UserGroup(answers=Counter({"a": 1, "b": 1, "c": 1}), size=1), - UserGroup(answers=Counter({"a": 1, "b": 1, "c": 1}), size=3), - UserGroup(answers=Counter({"a": 2, "b": 1, "c": 1}), size=2), - UserGroup(answers=Counter({"a": 4}), size=4), - UserGroup(answers=Counter({"b": 1}), size=1), - ] - assert day._calculate_2() == 6 diff --git a/tests/y_2020/test_2020_day7.py b/tests/y_2020/test_2020_day7.py deleted file mode 100644 index d564185..0000000 --- a/tests/y_2020/test_2020_day7.py +++ /dev/null @@ -1,92 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day7 import BagRule, Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [ - "light red bags contain 1 bright white bag, 2 muted yellow bags.", - "dark orange bags contain 3 bright white bags, 4 muted yellow bags.", - "bright white bags contain 1 shiny gold bag.", - "muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.", - "shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.", - "dark olive bags contain 3 faded blue bags, 4 dotted black bags.", - "vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.", - "faded blue bags contain no other bags.", - "dotted black bags contain no other bags.", - ] - day._preprocess_input() - assert day._Day__rules == { - "light#red": BagRule( - rules=[{"bright#white": 1}, {"muted#yellow": 2}], cache={}, extension={} - ), - "dark#orange": BagRule( - rules=[{"bright#white": 3}, {"muted#yellow": 4}], cache={}, extension={} - ), - "bright#white": BagRule(rules=[{"shiny#gold": 1}], cache={}, extension={}), - "muted#yellow": BagRule( - rules=[{"shiny#gold": 2}, {"faded#blue": 9}], cache={}, extension={} - ), - "shiny#gold": BagRule( - rules=[{"dark#olive": 1}, {"vibrant#plum": 2}], cache={}, extension={} - ), - "dark#olive": BagRule( - rules=[{"faded#blue": 3}, {"dotted#black": 4}], cache={}, extension={} - ), - "vibrant#plum": BagRule( - rules=[{"faded#blue": 5}, {"dotted#black": 6}], cache={}, extension={} - ), - "faded#blue": BagRule(rules=[{"no#other": 0}], cache={}, extension={}), - "dotted#black": BagRule(rules=[{"no#other": 0}], cache={}, extension={}), - "no#other": BagRule(rules=[], cache={}, extension={}), - } - - -def test_calculate_1(): - day._Day__rules = { - "light#red": BagRule( - rules=[{"bright#white": 1}, {"muted#yellow": 2}], cache={}, extension={} - ), - "dark#orange": BagRule( - rules=[{"bright#white": 3}, {"muted#yellow": 4}], cache={}, extension={} - ), - "bright#white": BagRule(rules=[{"shiny#gold": 1}], cache={}, extension={}), - "muted#yellow": BagRule( - rules=[{"shiny#gold": 2}, {"faded#blue": 9}], cache={}, extension={} - ), - "shiny#gold": BagRule( - rules=[{"dark#olive": 1}, {"vibrant#plum": 2}], cache={}, extension={} - ), - "dark#olive": BagRule( - rules=[{"faded#blue": 3}, {"dotted#black": 4}], cache={}, extension={} - ), - "vibrant#plum": BagRule( - rules=[{"faded#blue": 5}, {"dotted#black": 6}], cache={}, extension={} - ), - "faded#blue": BagRule(rules=[{"no#other": 0}], cache={}, extension={}), - "dotted#black": BagRule(rules=[{"no#other": 0}], cache={}, extension={}), - "no#other": BagRule(rules=[], cache={}, extension={}), - } - assert day._calculate_1() == 4 - - -def test_calculate_2(): - day._Day__rules = { - "shiny#gold": BagRule( - rules=[{"dark#olive": 1}, {"vibrant#plum": 2}], cache={}, extension={} - ), - "dark#olive": BagRule( - rules=[{"faded#blue": 3}, {"dotted#black": 4}], cache={}, extension={} - ), - "vibrant#plum": BagRule( - rules=[{"faded#blue": 5}, {"dotted#black": 6}], cache={}, extension={} - ), - "faded#blue": BagRule(rules=[{"no#other": 0}], cache={}, extension={}), - "dotted#black": BagRule(rules=[{"no#other": 0}], cache={}, extension={}), - "no#other": BagRule(rules=[], cache={}, extension={}), - } - assert day._calculate_2() == 32 diff --git a/tests/y_2020/test_2020_day8.py b/tests/y_2020/test_2020_day8.py deleted file mode 100644 index e6a46ea..0000000 --- a/tests/y_2020/test_2020_day8.py +++ /dev/null @@ -1,65 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day8 import Day, Instruction - -with patch("builtins.open", mock_open(read_data=" 0")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [ - "nop +0", - "acc +1", - "jmp +4", - "acc +3", - "jmp -3", - "acc -99", - "acc +1", - "jmp -4", - "acc +6", - ] - day._preprocess_input() - assert day._Day__instructions == [ - Instruction(operation="nop", argument=+0), - Instruction(operation="acc", argument=+1), - Instruction(operation="jmp", argument=+4), - Instruction(operation="acc", argument=+3), - Instruction(operation="jmp", argument=-3), - Instruction(operation="acc", argument=-99), - Instruction(operation="acc", argument=+1), - Instruction(operation="jmp", argument=-4), - Instruction(operation="acc", argument=+6), - ] - - -def test_calculate_1(): - print() - day._Day__instructions = [ - Instruction(operation="nop", argument=+0), - Instruction(operation="acc", argument=+1), - Instruction(operation="jmp", argument=+4), - Instruction(operation="acc", argument=+3), - Instruction(operation="jmp", argument=-3), - Instruction(operation="acc", argument=-99), - Instruction(operation="acc", argument=+1), - Instruction(operation="jmp", argument=-4), - Instruction(operation="acc", argument=+6), - ] - assert day._calculate_1() == 5 - - -def test_calculate_2(): - print() - day._Day__instructions = [ - Instruction(operation="nop", argument=+0), - Instruction(operation="acc", argument=+1), - Instruction(operation="jmp", argument=+4), - Instruction(operation="acc", argument=+3), - Instruction(operation="jmp", argument=-3), - Instruction(operation="acc", argument=-99), - Instruction(operation="acc", argument=+1), - Instruction(operation="jmp", argument=-4), - Instruction(operation="acc", argument=+6), - ] - assert day._calculate_2() == 8 diff --git a/tests/y_2020/test_2020_day9.py b/tests/y_2020/test_2020_day9.py deleted file mode 100644 index 7e77162..0000000 --- a/tests/y_2020/test_2020_day9.py +++ /dev/null @@ -1,109 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2020.day9 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - print() - day._input_data = [ - "35", - "20", - "15", - "25", - "47", - "40", - "62", - "55", - "65", - "95", - "102", - "117", - "150", - "182", - "127", - "219", - "299", - "277", - "309", - "576", - ] - day._preprocess_input() - assert day._Day__input == [ - 35, - 20, - 15, - 25, - 47, - 40, - 62, - 55, - 65, - 95, - 102, - 117, - 150, - 182, - 127, - 219, - 299, - 277, - 309, - 576, - ] - - -def test_calculate_1(): - print() - day._Day__input == [ - 35, - 20, - 15, - 25, - 47, - 40, - 62, - 55, - 65, - 95, - 102, - 117, - 150, - 182, - 127, - 219, - 299, - 277, - 309, - 576, - ] - assert day._calculate_1(5) == 127 - - -def test_calculate_2(): - print() - day._Day__input == [ - 35, - 20, - 15, - 25, - 47, - 40, - 62, - 55, - 65, - 95, - 102, - 117, - 150, - 182, - 127, - 219, - 299, - 277, - 309, - 576, - ] - assert day._calculate_2(127) == 62 diff --git a/tests/y_2020/test_utils.py b/tests/y_2020/test_utils.py deleted file mode 100644 index 2172944..0000000 --- a/tests/y_2020/test_utils.py +++ /dev/null @@ -1,16 +0,0 @@ -from y_2020.utils import collapse_strings, dict_from_string, prod - - -def test_prod(): - assert prod([]) == 1 - assert prod([1]) == 1 - assert prod([2, 3]) == 6 - - -def test_collapse_strings(): - assert collapse_strings(["x", "", "y1", "y2"]) == ["x", "y1 y2"] - assert collapse_strings(["x", "y", "", "z"]) == ["x y", "z"] - - -def test_dict_from_string(): - assert dict_from_string(":") == {"": ""} diff --git a/tests/y_2021/test_2021_common.py b/tests/y_2021/test_2021_common.py deleted file mode 100644 index 6b408c5..0000000 --- a/tests/y_2021/test_2021_common.py +++ /dev/null @@ -1,46 +0,0 @@ -import contextlib -from unittest.mock import patch - -from y_2021.common import AoCDay, load_input, main - - -def test_load_input_string(): - with patch("y_2021.common.open") as open_patch: - open_patch().__enter__().read = lambda: "hello" - assert load_input(0, 0) == ["hello"] - - -def test_load_input_multiline(): - with patch("y_2021.common.open") as open_patch: - open_patch().__enter__().read = lambda: "hello\nworld\n" - assert load_input(0, 0) == ["hello", "world"] - - -def test_main(): - with contextlib.ExitStack() as patches: - patches.enter_context(patch("y_2021.common.argparse")) - patches.enter_context(patch("y_2021.common.open")) - patches.enter_context(patch("y_2021.common.importlib")) - assert main() is None - - -class MockAoCDay(AoCDay): - def __init__(self): - super().__init__(0, 0) - - def _calculate_1(self): - pass - - def _calculate_2(self): - pass - - def _preprocess_input(self): - pass - - -def test_AoCDay(): - print() - with patch("y_2021.common.open") as open_patch: - open_patch().__enter__().read = lambda: "hello\nworld\n" - mock_aoc_day = MockAoCDay() - assert mock_aoc_day.solve() is None diff --git a/tests/y_2021/test_2021_day1.py b/tests/y_2021/test_2021_day1.py deleted file mode 100644 index 9ee77f5..0000000 --- a/tests/y_2021/test_2021_day1.py +++ /dev/null @@ -1,49 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2021.common import load_input -from y_2021.day1 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - day._input_data = [ - "199", - "200", - "208", - "210", - "200", - "207", - "240", - "269", - "260", - "263", - ] - day._preprocess_input() - assert day._Day__input_data == [199, 200, 208, 210, 200, 207, 240, 269, 260, 263] - - day._input_data = [] - day._preprocess_input() - assert day._Day__input_data == [] - - -def test_calculate_1(): - day._Day__input_data = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263] - assert day._calculate_1() == 7 - day._Day__input_data = [] - assert day._calculate_1() == 0 - - -def test_calculate_2(): - day._Day__input_data = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263] - assert day._calculate_2() == 5 - day._Day__input_data = [] - assert day._calculate_2() == 0 - - -def test_complete(): - day._input_data = load_input(1, 1) - day._preprocess_input() - assert day._calculate_1() == 7 - assert day._calculate_2() == 5 diff --git a/tests/y_2021/test_2021_day2.py b/tests/y_2021/test_2021_day2.py deleted file mode 100644 index 823de3a..0000000 --- a/tests/y_2021/test_2021_day2.py +++ /dev/null @@ -1,67 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2021.common import load_input -from y_2021.day2 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test__preprocess_input(): - day._input_data = [ - "forward 5", - "down 5", - "forward 8", - "up 3", - "down 8", - "forward 2", - ] - - day._preprocess_input() - assert day._Day__input_data == [ - "forward 5", - "down 5", - "forward 8", - "up 3", - "down 8", - "forward 2", - ] - - day._input_data = [] - day._preprocess_input() - assert day._Day__input_data == [] - - -def test_calculate_1(): - day._Day__input_data = [ - "forward 5", - "down 5", - "forward 8", - "up 3", - "down 8", - "forward 2", - ] - assert day._calculate_1() == 150 - day._Day__input_data = [] - assert day._calculate_1() == 0 - - -def test_calculate_2(): - day._Day__input_data = [ - "forward 5", - "down 5", - "forward 8", - "up 3", - "down 8", - "forward 2", - ] - assert day._calculate_2() == 900 - day._Day__input_data = [] - assert day._calculate_2() == 0 - - -def test_complete(): - day._input_data = load_input(__name__.replace("test_2021_day", ""), 1) - day._preprocess_input() - assert day._calculate_1() == 150 - assert day._calculate_2() == 900 diff --git a/tests/y_2021/test_2021_day3.py b/tests/y_2021/test_2021_day3.py deleted file mode 100644 index 873f3a2..0000000 --- a/tests/y_2021/test_2021_day3.py +++ /dev/null @@ -1,14 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2021.common import load_input -from y_2021.day3 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test_complete(): - day._input_data = load_input(__name__.replace("test_2021_day", ""), 1) - day._preprocess_input() - assert day._calculate_1() == 198 - assert day._calculate_2() == 230 diff --git a/tests/y_2021/test_2021_day4.py b/tests/y_2021/test_2021_day4.py deleted file mode 100644 index 6e3d0fd..0000000 --- a/tests/y_2021/test_2021_day4.py +++ /dev/null @@ -1,14 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2021.common import load_input -from y_2021.day4 import Day - -with patch("builtins.open", mock_open(read_data=",")): - day = Day() - - -def test_complete(): - day._input_data = load_input(__name__.replace("test_2021_day", ""), 1) - day._preprocess_input() - assert day._calculate_1() == 4512 - assert day._calculate_2() == 1924 diff --git a/tests/y_2021/test_2021_day5.py b/tests/y_2021/test_2021_day5.py deleted file mode 100644 index 033726c..0000000 --- a/tests/y_2021/test_2021_day5.py +++ /dev/null @@ -1,14 +0,0 @@ -from unittest.mock import mock_open, patch - -from y_2021.common import load_input -from y_2021.day5 import Day - -with patch("builtins.open", mock_open(read_data="")): - day = Day() - - -def test_complete(): - day._input_data = load_input(__name__.replace("test_2021_day", ""), 1) - day._preprocess_input() - assert day._calculate_1() == 5 - assert day._calculate_2() == 12 diff --git a/tests/y_2021/test_2021_utils.py b/tests/y_2021/test_2021_utils.py deleted file mode 100644 index 09fb24e..0000000 --- a/tests/y_2021/test_2021_utils.py +++ /dev/null @@ -1,10 +0,0 @@ -from y_2021.utils import decimal_from_binary - - -def test_decimal_from_binary(): - assert decimal_from_binary([]) == 0 - assert decimal_from_binary([0]) == 0 - assert decimal_from_binary([1]) == 1 - assert decimal_from_binary([1, 0]) == 2 - assert decimal_from_binary([1, 1, 0]) == 6 - assert decimal_from_binary([1, 1, 1]) == 7 diff --git a/y_2015/__init__.py b/y_2015/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/y_2015/common.py b/y_2015/common.py deleted file mode 100644 index c262c55..0000000 --- a/y_2015/common.py +++ /dev/null @@ -1,32 +0,0 @@ -import argparse -import importlib - - -def load_input(day): - with open(f"y_2015/input_day{day}.txt") as f: - x = (f.read()).split("\n") - if x[-1] == "": - del x[-1] - return x - - -def main(): - """""" - parser = argparse.ArgumentParser() - parser.add_argument("day", type=int, help="day as a number") - args = parser.parse_args() - - x = load_input(args.day) - - day = importlib.import_module(f"day{args.day}") - - if args.day in (6, 7): - print(f"sol 1: {day.calculate_1(x)}") - print(f"sol 2: {day.calculate_2(x)}") - else: - print(f"sol 1: {sum(day.calculate_1(i) for i in x)}") - print(f"sol 2: {sum(day.calculate_2(i) for i in x)}") - - -if __name__ == "__main__": - main() diff --git a/y_2015/day2.py b/y_2015/day2.py deleted file mode 100644 index b1f3749..0000000 --- a/y_2015/day2.py +++ /dev/null @@ -1,18 +0,0 @@ -from typing import List - - -def get_measures(i: str) -> List: - return [int(x) for x in i.split("x")] - - -def calculate_1(i: str) -> int: - l, w, h = get_measures(i) - small_area = min(l * w, l * h, w * h) - return 2 * l * w + 2 * w * h + 2 * h * l + small_area - - -def calculate_2(i: str) -> int: - measures = get_measures(i) - l, w, h = measures - small_perimeter = sum(2 * x for x in sorted(measures)[:-1]) - return small_perimeter + l * w * h diff --git a/y_2015/day3.py b/y_2015/day3.py deleted file mode 100644 index 37841a3..0000000 --- a/y_2015/day3.py +++ /dev/null @@ -1,26 +0,0 @@ -from collections import defaultdict -from typing import DefaultDict, List - -OPERATIONS = {">": (1, 0), "<": (-1, 0), "^": (0, 1), "v": (0, -1)} - - -def deliver(i: str, actors: List) -> int: - grid: DefaultDict[tuple, int] = defaultdict(int) - actor_location = [[1, 1] for i in actors] - grid[(1, 1)] = 1 - current_actor = 0 - for j in i: - moves = OPERATIONS[j] - actor_location[current_actor][0] += moves[0] - actor_location[current_actor][1] += moves[1] - grid[tuple(actor_location[current_actor])] = 1 - current_actor = (current_actor + 1) % len(actors) - return len(grid) - - -def calculate_1(i: str) -> int: - return deliver(i, ["santa"]) - - -def calculate_2(i: str) -> int: - return deliver(i, ["santa", "robo-santa"]) diff --git a/y_2015/day4.py b/y_2015/day4.py deleted file mode 100644 index 42585ca..0000000 --- a/y_2015/day4.py +++ /dev/null @@ -1,18 +0,0 @@ -import hashlib - - -def hash_logic(i: str, num_zeros: int) -> int: - n = 0 - while True: - result = hashlib.md5(i.encode("ascii") + str(n).encode("ascii")).hexdigest() - if result[:num_zeros] == "0" * num_zeros: - return n - n += 1 - - -def calculate_1(i: str) -> int: - return hash_logic(i, 5) - - -def calculate_2(i: str) -> int: - return hash_logic(i, 6) diff --git a/y_2015/day5.py b/y_2015/day5.py deleted file mode 100644 index 3c67af9..0000000 --- a/y_2015/day5.py +++ /dev/null @@ -1,46 +0,0 @@ -from collections import defaultdict -from typing import DefaultDict - - -def calculate_1(i: str) -> int: - twice = False - contains_bad_string = False - vowels_count = sum(1 for letter in i if letter in ["a", "e", "i", "o", "u"]) - for j, l in enumerate(i): - if j == 0: - continue - if i[j - 1] == l: - twice = True - if i[j - 1] + l in ["ab", "cd", "pq", "xy"]: - contains_bad_string = True - return int(vowels_count >= 3 and twice and not contains_bad_string) - - -def twiced(i: str) -> bool: - pairs: DefaultDict[tuple, int] = defaultdict(int) - for j, l in enumerate(i): - if j == 0: - continue - if ( - (j <= 1) - or (i[j - 2] != i[j - 1] or i[j - 1] != i[j]) - or (j > 2 and i[j - 3] == i[j - 2]) - ): - pairs[(i[j - 1], l)] += 1 - - return any(pairs[j] > 1 for j in pairs) - - -def repeated(i: str) -> int: - for j, l in enumerate(i): - if j <= 1: - continue - if i[j - 2] == l: - return True - return False - - -def calculate_2(i: str) -> int: - twice = twiced(i) - repeat = repeated(i) - return int(twice and repeat) diff --git a/y_2015/day6.py b/y_2015/day6.py deleted file mode 100644 index bff4533..0000000 --- a/y_2015/day6.py +++ /dev/null @@ -1,52 +0,0 @@ -import re -from collections import defaultdict -from typing import DefaultDict - -GRID: DefaultDict[tuple, int] = defaultdict(int) - - -def parse(i): - command = i[: re.search(" \d", i).start()] # noqa W605 - positions = re.findall("[\d]+,[\d]+", i) # noqa W605 - return ( - command, - tuple(int(x) for x in positions[0].split(",")), - "through", - tuple(int(x) for x in positions[1].split(",")), - ) - - -def operate_ligths(i: str) -> None: - command, start, _, end = parse(i) - for j in range(start[0], end[0] + 1): - for k in range(start[1], end[1] + 1): - if command == "toggle": - GRID[(j, k)] = 1 - GRID[(j, k)] - elif command == "turn off": - GRID[(j, k)] = 0 - elif command == "turn on": - GRID[(j, k)] = 1 - - -def operate_ligths_second(i: str) -> None: - command, start, _, end = parse(i) - for j in range(start[0], end[0] + 1): - for k in range(start[1], end[1] + 1): - if command == "toggle": - GRID[(j, k)] = GRID[(j, k)] + 2 - elif command == "turn off": - GRID[(j, k)] = max(GRID[(j, k)] - 1, 0) - elif command == "turn on": - GRID[(j, k)] = GRID[(j, k)] + 1 - - -def calculate_1(x: list) -> int: - for i in x: - operate_ligths(i) - return sum(GRID[j] for j in GRID) - - -def calculate_2(x: str) -> int: - for i in x: - operate_ligths_second(i) - return sum(GRID[j] for j in GRID) diff --git a/y_2015/day7.py b/y_2015/day7.py deleted file mode 100644 index de5ddae..0000000 --- a/y_2015/day7.py +++ /dev/null @@ -1,167 +0,0 @@ -import re -from collections import defaultdict - - -def bitand(x, y): - return x & y - - -def bitor(x, y): - return x | y - - -def lshift(x, y): - return x << y - - -def rshift(x, y): - return x >> y - - -def bitnot(x): - return x ^ 65535 - - -BIN_OPERATORS = {"AND": bitand, "OR": bitor, "LSHIFT": lshift, "RSHIFT": rshift} -UN_OPERATORS = {"NOT": bitnot} - - -class Container: - content = None - - -class Link: - """docstring for Link""" - - @staticmethod - def get_link_from_value(x): - try: - value = int(x) - return ValueLink(value) - except ValueError: - pass - return DirectLink(WIRING[x]) - - @staticmethod - def create_link(rule): - if len(rule) == 1: - return Link.get_link_from_value(rule[0]) - - if rule[0] in BIN_OPERATORS: - return BinaryLink( - rule[0], - Link.get_link_from_value(rule[1]), - Link.get_link_from_value(rule[2]), - ) - - if rule[0] in UN_OPERATORS: - return UnaryLink(rule[0], Link.get_link_from_value(rule[1])) - - def __init__(self, operator=None): - self._cached_result = None - self._operator = operator - - def get_value(self): - if not self._cached_result: - self._cached_result = self._get_value() - return self._cached_result - - -class ValueLink(Link): - """""" - - def __init__(self, value): - self.__value = value - super().__init__() - - def _get_value(self): - return self.__value - - def set_value(self, value): - self.__value = value - - -class DirectLink(Link): - """""" - - def __init__(self, op1): - self._op1 = op1 - super().__init__() - - def _get_value(self): - return self._op1.content.get_value() - - -class BinaryLink(Link): - """""" - - def __init__(self, operator, op1, op2): - self._op1 = op1 - self._op2 = op2 - super().__init__(operator) - - def _get_value(self): - return BIN_OPERATORS[self._operator]( - self._op1.get_value(), self._op2.get_value() - ) - - -class UnaryLink(Link): - def __init__(self, operator, op1): - self._op1 = op1 - super().__init__(operator) - - def _get_value(self): - return UN_OPERATORS[self._operator](self._op1.get_value()) - - -WIRING = defaultdict(Container) - - -def parse(i): - x = i[: re.search(" ->", i).start()] - if opcode_match := re.findall("|".join(BIN_OPERATORS), x): - opcode = opcode_match[0] - first = x[: re.search(f" {opcode}", x).start()] - second = x[re.search(f"{opcode}", x).start() + len(opcode) + 1 :] - - return [i[re.search(" ->", i).start() + 4 :], f"{opcode}", first, second] - - if opcode_match := re.findall("|".join(UN_OPERATORS), x): - opcode = opcode_match[0] - second = x[re.search(f"{opcode}", x).start() + len(opcode) + 1 :] - return [i[re.search(" ->", i).start() + 4 :], f"{opcode}", second] - - return [i[re.search(" ->", i).start() + 4 :], i[: re.search(" ->", i).start()]] - - -def inner_1(lista): - global WIRING - WIRING = defaultdict(Container) - parsedl = [parse(i) for i in lista] - for i in parsedl: - temp = WIRING[i[0]] - temp.content = Link.create_link(i[1:]) - - return {k: v.content.get_value() for k, v in WIRING.items()} - - -def calculate_1(x: list) -> int: - result = inner_1(x) - return result["a"] - - -def inner_2(lista): - global WIRING - WIRING = defaultdict(Container) - parsedl = [parse(i) for i in lista] - for i in parsedl: - temp = WIRING[i[0]] - temp.content = Link.create_link(i[1:]) - WIRING["b"].content.set_value(46065) - return {k: v.content.get_value() for k, v in WIRING.items()} - - -def calculate_2(x: str) -> int: - result = inner_2(x) - return result["a"] diff --git a/y_2019/__init__.py b/y_2019/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/y_2019/__main__.py b/y_2019/__main__.py deleted file mode 100644 index 35979d7..0000000 --- a/y_2019/__main__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .common import main - -if __name__ == "__main__": - main() diff --git a/y_2019/common.py b/y_2019/common.py deleted file mode 100644 index 3012507..0000000 --- a/y_2019/common.py +++ /dev/null @@ -1,60 +0,0 @@ -import argparse -import importlib -from abc import ABC, abstractmethod - - -class AoCDay(ABC): - """ - Abstract class Day - """ - - @abstractmethod - def __init__(self, day): - self._input_data = load_input(day) - self._preprocess_input() - - @abstractmethod - def _preprocess_input(self): - """ - preprocessing of the input - """ - - @abstractmethod - def _calculate_1(self): - """ - _calculate_1 - """ - - @abstractmethod - def _calculate_2(self): - """ - _calculate_2 - """ - - def solve(self): - print(f"sol 1: {self._calculate_1()}") - print(f"sol 2: {self._calculate_2()}") - - -def load_input(day): - with open(f"y_2019/input_day{day}.txt") as f: - x = (f.read()).split("\n") - if x[-1] == "": - del x[-1] - return x - - -def main(): - """""" - parser = argparse.ArgumentParser() - parser.add_argument("day", type=int, help="day as a number") - args = parser.parse_args() - - module = importlib.import_module(f"y_2019.day{args.day}") - - day = getattr(module, "Day")() - day.solve() - - -if __name__ == "__main__": - main() diff --git a/y_2019/day1.py b/y_2019/day1.py deleted file mode 100644 index 14b9d2d..0000000 --- a/y_2019/day1.py +++ /dev/null @@ -1,25 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(1) - - def _preprocess_input(self): - self.__mass_list = [int(i) for i in self._input_data] - - def _calculate_1(self): - return sum(self.fuel_from_mass(mass) for mass in self.__mass_list) - - def _calculate_2(self): - return sum(self.total_fuel_from_mass(mass) for mass in self.__mass_list) - - @staticmethod - def fuel_from_mass(mass): - return mass // 3 - 2 - - @staticmethod - def total_fuel_from_mass(mass): - if (w := Day.fuel_from_mass(mass)) < 0: - return 0 - return w + Day.total_fuel_from_mass(w) diff --git a/y_2020/__init__.py b/y_2020/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/y_2020/__main__.py b/y_2020/__main__.py deleted file mode 100644 index 35979d7..0000000 --- a/y_2020/__main__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .common import main - -if __name__ == "__main__": - main() diff --git a/y_2020/common.py b/y_2020/common.py deleted file mode 100644 index 91d156e..0000000 --- a/y_2020/common.py +++ /dev/null @@ -1,78 +0,0 @@ -import argparse -import importlib -from abc import ABC, abstractmethod -from datetime import datetime - - -class StopWatch: - def __init__(self): - self.__start_time = None - - def start(self): - self.__start_time = datetime.now() - - def lap(self): - return datetime.now() - self.__start_time - - def stop(self): - return datetime.now() - self.__start_time - - -class AoCDay(ABC): - """ - Abstract class Day - """ - - @abstractmethod - def __init__(self, day): - self._input_data = load_input(day) - self._preprocess_input() - self.__stop_watch = StopWatch() - - @abstractmethod - def _preprocess_input(self): - """ - preprocessing of the input - """ - - @abstractmethod - def _calculate_1(self): - """ - _calculate_1 - """ - - @abstractmethod - def _calculate_2(self): - """ - _calculate_2 - """ - - def solve(self): - self.__stop_watch.start() - print(f"sol 1: {self._calculate_1()} Time taken: {self.__stop_watch.lap()}") - - print(f"sol 2: {self._calculate_2()} Time taken: {self.__stop_watch.stop()}") - - -def load_input(day): - with open(f"y_2020/input_day{day}.txt") as f: - x = (f.read()).split("\n") - if x[-1] == "": - del x[-1] - return x - - -def main(): - """""" - parser = argparse.ArgumentParser() - parser.add_argument("day", type=int, help="day as a number") - args = parser.parse_args() - - module = importlib.import_module(f"y_2020.day{args.day}") - - day = getattr(module, "Day")() - day.solve() - - -if __name__ == "__main__": - main() diff --git a/y_2020/day1.py b/y_2020/day1.py deleted file mode 100644 index bb4e34d..0000000 --- a/y_2020/day1.py +++ /dev/null @@ -1,30 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(1) - - def _preprocess_input(self): - self.__input_data = [int(i) for i in self._input_data] - - def _calculate_1(self): - y = self.__input_data - - for i in y: - for j in y: - if (i + j) == 2020: - return i * j - - return 0 - - def _calculate_2(self): - y = self.__input_data - - for i in y: - for j in y: - for k in y: - if (i + j + k) == 2020: - return i * j * k - - return 0 diff --git a/y_2020/day10.py b/y_2020/day10.py deleted file mode 100644 index 08467a9..0000000 --- a/y_2020/day10.py +++ /dev/null @@ -1,44 +0,0 @@ -from collections import defaultdict - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(10) - - def _preprocess_input(self): - self.__input = [int(i) for i in self._input_data] - - def _calculate_1(self): - y = sorted(self.__input) - j1 = 0 - j3 = 0 - for i in range(1, len(y)): - if y[i] == y[i - 1] + 1: - j1 += 1 - else: - j3 += 1 - return (j1 + 1) * (j3 + 1) - - def _calculate_2(self): - y = sorted(self.__input) - y = [0] + y + [y[-1] + 3] - d = defaultdict(int) - counter = 1 - for i in range(1, len(y)): - contiguous = y[i] == y[i - 1] + 1 - if contiguous: - counter += 1 - else: - d[counter] += 1 - counter = 1 - res = 1 - for i in d: - x = 1 - if i >= 5: - x = (2 ** (i - 2) - 1) ** d[i] - elif i > 2: - x = (2 ** (i - 2)) ** d[i] - res *= x - return res diff --git a/y_2020/day11.py b/y_2020/day11.py deleted file mode 100644 index bf4ca9b..0000000 --- a/y_2020/day11.py +++ /dev/null @@ -1,159 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(11) - - def _preprocess_input(self): - self.__input = [i for i in self._input_data] - self.__lenght = len(self.__input) - self.__width = len(self.__input[0]) - - def __generate_adjacent(self, i, j): - u = i - 1 - r = j + 1 - d = i + 1 - l = j - 1 - # clockwise - c1 = self.__input[u][j] if u >= 0 else None - c2 = self.__input[u][r] if u >= 0 and r <= self.__width - 1 else None - c3 = self.__input[i][r] if r <= self.__width - 1 else None - c4 = ( - self.__input[d][r] - if d <= self.__lenght - 1 and r <= self.__width - 1 - else None - ) - c5 = self.__input[d][j] if d <= self.__lenght - 1 else None - c6 = self.__input[d][l] if d <= self.__lenght - 1 and l >= 0 else None - c7 = self.__input[i][l] if l >= 0 else None - c8 = self.__input[u][l] if u >= 0 and l >= 0 else None - return [c1, c2, c3, c4, c5, c6, c7, c8] - - def __generate_visible(self, i, j): - u = i - 1 - r = j + 1 - d = i + 1 - l = j - 1 - # clockwise - c1 = self.__input[u][j] if u >= 0 else None - u1 = u - while c1 == ".": - if c1 not in ["L", "#"]: - u1 = u1 - 1 - c1 = self.__input[u1][j] if u1 >= 0 else None - - c2 = self.__input[u][r] if u >= 0 and r <= len(self.__input[i]) - 1 else None - u2 = u - r2 = r - while c2 == ".": - if c2 not in ["L", "#"]: - u2 = u2 - 1 - r2 = r2 + 1 - c2 = ( - self.__input[u2][r2] - if u2 >= 0 and r2 <= len(self.__input[i]) - 1 - else None - ) - - c3 = self.__input[i][r] if r <= len(self.__input[i]) - 1 else None - r3 = r - while c3 == ".": - if c3 not in ["L", "#"]: - r3 = r3 + 1 - c3 = self.__input[i][r3] if r3 <= len(self.__input[i]) - 1 else None - - c4 = ( - self.__input[d][r] - if d <= len(self.__input) - 1 and r <= len(self.__input[i]) - 1 - else None - ) - d4 = d - r4 = r - while c4 == ".": - if c4 not in ["L", "#"]: - r4 = r4 + 1 - d4 = d4 + 1 - c4 = ( - self.__input[d4][r4] - if d4 <= len(self.__input) - 1 and r4 <= len(self.__input[i]) - 1 - else None - ) - - c5 = self.__input[d][j] if d <= len(self.__input) - 1 else None - d5 = d - while c5 == ".": - if c5 not in ["L", "#"]: - d5 = d5 + 1 - c5 = self.__input[d5][j] if d5 <= len(self.__input) - 1 else None - - c6 = self.__input[d][l] if d <= len(self.__input) - 1 and l >= 0 else None - d6 = d - l6 = l - while c6 == ".": - if c6 not in ["L", "#"]: - d6 = d6 + 1 - l6 = l6 - 1 - c6 = ( - self.__input[d6][l6] - if d6 <= len(self.__input) - 1 and l6 >= 0 - else None - ) - - c7 = self.__input[i][l] if l >= 0 else None - l7 = l - while c7 == ".": - if c7 not in ["L", "#"]: - l7 = l7 - 1 - c7 = self.__input[i][l7] if l7 >= 0 else None - - c8 = self.__input[u][l] if u >= 0 and l >= 0 else None - u8 = u - l8 = l - while c8 == ".": - if c8 not in ["L", "#"]: - u8 = u8 - 1 - l8 = l8 - 1 - c8 = self.__input[u8][l8] if u8 >= 0 and l8 >= 0 else None - - return [c1, c2, c3, c4, c5, c6, c7, c8] - - def __iterate(self, proximity, seats_leave): - new_seating = [] - for i in range(self.__lenght): - new_seating.append([]) - for j in range(self.__width): - adj = proximity(i, j) - - temp = self.__input[i][j] - if self.__input[i][j] == "L" and sum(i == "#" for i in adj) == 0: - temp = "#" - if ( - self.__input[i][j] == "#" - and sum(i == "#" for i in adj) >= seats_leave - ): - temp = "L" - new_seating[i].append(temp) - - self.__input = ["".join(i) for i in new_seating] - - def __iterate_adjacent(self): - self.__iterate(self.__generate_adjacent, 4) - - def __iterate_visible(self): - self.__iterate(self.__generate_visible, 5) - - def count_after_iterations(self, iteration_function): - while True: - before = str(self.__input) - iteration_function() - if before == str(self.__input): - break - - return sum(j == "#" for i in self.__input for j in i) - - def _calculate_1(self): - return self.count_after_iterations(self.__iterate_adjacent) - - def _calculate_2(self): - return self.count_after_iterations(self.__iterate_visible) diff --git a/y_2020/day12.py b/y_2020/day12.py deleted file mode 100644 index c1f77cc..0000000 --- a/y_2020/day12.py +++ /dev/null @@ -1,89 +0,0 @@ -from .common import AoCDay - -DIRECTIONS = ["N", "E", "S", "W"] -DEGREES = {90: 1, 180: 2, 270: 3} - - -class Day(AoCDay): - def __init__(self): - super().__init__(12) - - def _preprocess_input(self): - self.__input = [(i[0], int(i[1:])) for i in self._input_data] - - def _rotate(self, dir, degree, order): - x = 1 - if order != "R": - x = -1 - - for c, i in enumerate(DIRECTIONS): - if i == dir: - return DIRECTIONS[(c + x * DEGREES[degree]) % 4] - - def _calculate_1(self): - pos = (0, 0) - - direction = "E" - MOVES = { - "E": (0, 1), - "W": (0, -1), - "N": (1, 0), - "S": (-1, 0), - } - for i in self.__input: - if i[0] == "F": - pos = ( - pos[0] + MOVES[direction][0] * i[1], - pos[1] + MOVES[direction][1] * i[1], - ) - if i[0] == "E": - pos = (pos[0], pos[1] + i[1]) - if i[0] == "W": - pos = (pos[0], pos[1] - i[1]) - if i[0] == "N": - pos = (pos[0] + i[1], pos[1]) - if i[0] == "S": - pos = (pos[0] - i[1], pos[1]) - if i[0] == "L": - direction = self._rotate(direction, i[1], "L") - if i[0] == "R": - direction = self._rotate(direction, i[1], "R") - - return abs(pos[0]) + abs(pos[1]) - - def _calculate_2(self): - waypoint_pos = (1, 10) - pos = (0, 0) - for i in self.__input: - increment = (waypoint_pos[0] - pos[0], waypoint_pos[1] - pos[1]) - if i[0] == "F": - for _ in range(i[1]): - pos = ( - pos[0] + increment[0], # - pos[0], - pos[1] + increment[1], # - pos[1], - ) - waypoint_pos = (pos[0] + increment[0], pos[1] + increment[1]) - if i[0] == "E": - waypoint_pos = (waypoint_pos[0], waypoint_pos[1] + i[1]) - if i[0] == "W": - waypoint_pos = (waypoint_pos[0], waypoint_pos[1] - i[1]) - if i[0] == "N": - waypoint_pos = (waypoint_pos[0] + i[1], waypoint_pos[1]) - if i[0] == "S": - waypoint_pos = (waypoint_pos[0] - i[1], waypoint_pos[1]) - if i[0] == "L": - if i[1] == 90: - waypoint_pos = (pos[0] + increment[1], pos[1] - increment[0]) - if i[1] == 180: - waypoint_pos = (pos[0] - increment[0], pos[1] - increment[1]) - if i[1] == 270: - waypoint_pos = (pos[0] - increment[1], pos[1] + increment[0]) - if i[0] == "R": - if i[1] == 90: - waypoint_pos = (pos[0] - increment[1], pos[1] + increment[0]) - if i[1] == 180: - waypoint_pos = (pos[0] - increment[0], pos[1] - increment[1]) - if i[1] == 270: - waypoint_pos = (pos[0] + increment[1], pos[1] - increment[0]) - - return abs(pos[0]) + abs(pos[1]) diff --git a/y_2020/day13.py b/y_2020/day13.py deleted file mode 100644 index 88fd8d7..0000000 --- a/y_2020/day13.py +++ /dev/null @@ -1,66 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(13) - - def _preprocess_input(self): - self.__input = [i for i in self._input_data] - - def _calculate_1(self): - # info(self._input_data) - # print(*self._input_data, sep="\n") - # y = [int(i) for i in self._input_data.split(",")] - # print(sum(y)) - print(self.__input) - arr = int(self.__input[0]) - buses = [int(i) for i in self.__input[1].split(",") if i != "x"] - print(f"{buses=}") - schedule = {} # defaultdict(int) - for i in buses: - c = 0 - schedule[i] = [] - while True: - c += 1 - schedule[i].append(i * c) - if i * c > arr * 2: - break - # print(f"{schedule=}") - mins = {} - for k, v in schedule.items(): - for i in v: - if i >= arr: - mins[k] = i - break - # print(f"{mins=}") - min_x = min([m for m in mins.values()]) - min_x = arr * 10 - for k, v in mins.items(): - if v < min_x: - min_x = v - bus_id = k - - print(f"{min_x=}") - return (min_x - arr) * bus_id - - def _calculate_2(self): - buses = { - int(value): position - for position, value in enumerate(self.__input[1].split(",")) - if value != "x" - } - print(f"{buses=}") - - time = 0 - step = 1 - - for value, gap in buses.items(): - # print(f"{value=}, {gap=}") - for i in range(time, step * value, step): - # print(f"{i=}, {(i + gap)=}, {(i + gap) % value=}") - if not (i + gap) % value: - step = step * value - time = i - break - return time diff --git a/y_2020/day14.py b/y_2020/day14.py deleted file mode 100644 index 9b50123..0000000 --- a/y_2020/day14.py +++ /dev/null @@ -1,189 +0,0 @@ -import copy - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(14) - - def _preprocess_input(self): - # print(f"{self._input_data}") - self.__input = [i for i in self._input_data] - # print(f"{self.__input}") - self.__memory = {} - - def _calculate_1(self): - # info(self._input_data) - print("here") - # breakpoint() - print(f"{self.__input}") - instr = {} - instr["instr"] = [] - instr["new"] = [] - for i in self.__input: - # print(f"{i.split(' ')=}") - x = i.split(" ") - if x[0] == "mask": - temp_mask = x[2] - else: - # breakpoint() - instr["instr"].append((x[0][4:-1], int(x[2]), temp_mask)) - - len_mask = len(instr["instr"][0][2]) - for i in instr["instr"]: - binary_rep = "{0:b}".format(i[1]) - # print(binary_rep) - transformed = [] - print(f"{instr=}") - for j in range(len_mask): - # print(binary_rep[len(binary_rep) - j - 1]) - # print(f"{instr['mask']=}") - # print(f"{instr['mask'][len(instr['mask']) - j - 1]=}") - if i[2][len_mask - j - 1] == "X": - # print(f"{len(binary_rep)=}, {len(instr['mask'])=}, {j=}") - if j <= len(binary_rep) - 1: - transformed.append(binary_rep[len(binary_rep) - j - 1]) - else: - transformed.append("0") - elif i[2][len_mask - j - 1] == "1": - transformed.append("1") - elif i[2][len_mask - j - 1] == "0": - transformed.append("0") - # print(f"{transformed=}") - transformed.reverse() - instr["new"].append(int("".join(transformed), 2)) - # print(("".join(transformed))) - # print(int("".join(transformed), 2)) - print(instr) - for c, i in enumerate(instr["new"]): - print(f"{i=}") - print(f"{instr['instr'][c][0]=}") - self.__memory[instr["instr"][c][0]] = i - print(self.__memory) - res = 0 - for k, i in self.__memory.items(): - res = res + i - # temp = [i for i in self._input_data.split(",")] - # print(temp) - # print(*self._input_data, sep="\n") - # y = [int(i) for i in self._input_data.split(",")] - # print(sum(y)) - self.__input - return res - - def _calculate_2(self): - self.__memory = {} - instr = {} - instr["instr"] = [] - instr["new"] = [] - for i in self.__input: - # print(f"{i.split(' ')=}") - x = i.split(" ") - if x[0] == "mask": - temp_mask = x[2] - else: - instr["instr"].append((x[0][4:-1], int(x[2]), temp_mask)) - - print(f"{instr=}") - len_mask = len(instr["instr"][0][2]) - for i in instr["instr"]: - # print(f"{i=}") - # breakpoint() - binary_rep = "{0:b}".format(int(i[0])) - # print(f"{binary_rep=}") - transformed = [] - # print(f"{i=}") - # continue - for j in range(len_mask): - # print(binary_rep[len(binary_rep) - j - 1]) - # print(f"{instr['mask']=}") - # print(f"{instr['mask'][len(instr['mask']) - j - 1]=}") - if i[2][len_mask - j - 1] == "0": - # print(f"{len(binary_rep)=}, {len(instr['mask'])=}, {j=}") - if j <= len(binary_rep) - 1: - transformed.append(binary_rep[len(binary_rep) - j - 1]) - else: - transformed.append("0") - elif i[2][len_mask - j - 1] == "1": - transformed.append("1") - elif i[2][len_mask - j - 1] == "X": - transformed.append("#") - # print(f"{transformed=}") - transformed.reverse() - # instr["new"].append(int("".join(transformed), 2)) - instr["new"].append(("".join(transformed))) - # print(("".join(transformed))) - # print(int("".join(transformed), 2)) - print(instr) - mem_cells = [] - for i in instr["new"]: - out = [] - out.append([]) - # print(f"{i=}") - for j in i: - # print(f"{j=}, {i=}, {out=}") - if j == "0": - # do nothing - for k in out: - k.append("0") - # print(f"{out[-1]=}") - elif j == "1": - # do nothing - for k in out: - k.append("1") - # print(f"{out[-1]=}") - elif j == "#": - # generate - temp = copy.deepcopy(out) - # print(f"{temp=}") - # print(f"{out=}") - out.extend(temp) - # print(f"{out=}") - # breakpoint() - - for c, k in enumerate(out): - # print(f"{out=}{k=}") - if c < len(out) / 2: - k.append("0") - else: - k.append("1") - # print(f"{out=}") - memories = [] - for o in out: - print("".join(o)) - memories.append(int("".join(o), 2)) - mem_cells.append(memories) - - print(instr) - print(mem_cells) - - for c, i in enumerate(instr["instr"]): - # print(i) - # print(mem_cells[c]) - for j in mem_cells[c]: - self.__memory[j] = i[1] - print(f"{self.__memory=}") - - res = 0 - for k, i in self.__memory.items(): - res = res + i - - return res - - return - for c, i in enumerate(instr["new"]): - print(f"{i=}") - print(f"{instr['instr'][c][0]=}") - self.__memory[instr["instr"][c][0]] = i - print(self.__memory) - res = 0 - for k, i in self.__memory.items(): - res = res + i - # temp = [i for i in self._input_data.split(",")] - # print(temp) - # print(*self._input_data, sep="\n") - # y = [int(i) for i in self._input_data.split(",")] - # print(sum(y)) - self.__input - return res diff --git a/y_2020/day15.py b/y_2020/day15.py deleted file mode 100644 index 51a681c..0000000 --- a/y_2020/day15.py +++ /dev/null @@ -1,41 +0,0 @@ -from collections import defaultdict - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(15) - - def _preprocess_input(self): - self.__input = [i for i in self._input_data] - - def _calculate_1(self, stop=2020): - last = {} - before_last = {} - d = defaultdict(int) - list = self.__input[0].split(",") - c = 0 - t = 0 - prev = None - while t < stop: - if t < len(list): - spoken = int(list[c]) - else: - if d[prev] == 1: - spoken = 0 - else: - if prev in before_last: - spoken = last[prev] - before_last[prev] - d[spoken] += 1 - c = (c + 1) % len(list) - t += 1 - prev = spoken - if spoken in last: - before_last[spoken] = last[spoken] - last[spoken] = t - - return spoken - - def _calculate_2(self): - return self._calculate_1(30000000) diff --git a/y_2020/day16.py b/y_2020/day16.py deleted file mode 100644 index 48805b2..0000000 --- a/y_2020/day16.py +++ /dev/null @@ -1,182 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(16) - - def _preprocess_input(self): - self.__input = [i for i in self._input_data] - - def _calculate_1(self): - # info(self._input_data) - # return 0 - rules = {} - # yours = [] - others = [] - rules_flag = True - # your = False - other = False - for i in self.__input: - # print(i) - if i == "": - rules_flag = False - if i == "your ticket:": - # your = True - continue - if i == "nearby tickets:": - other = True - continue - if rules_flag: - # print(i) - # print(i[: i.index(":")]) - # print(i[i.index(":") + 2 :].split(" or ")) - rules[i[: i.index(":")]] = i[i.index(":") + 2 :].split(" or ") - # if your: - # # print(i.split()) - # yours = i.split(",") - if other: - others.append(i.split(",")) - - # print(rules) - # print(yours) - # print(others) - result = 0 - for i in others: - # print(i) - for j in i: - valid = False - # print(j) - for k, v in rules.items(): - # print(f"{k=}, {v=}, {j=}") - for c in range(2): - a = int(v[c].split("-")[0]) - b = int(v[c].split("-")[1]) - # print(f"{j=},{a=},{b=},{a <= int(j) <= b=}") - if a <= int(j) <= b: - valid = True - if not valid: - # print(f"not valid: {j=}") - result += int(j) - return result - - def _calculate_2(self): - # info(self._input_data) - rules = {} - yours = [] - others = [] - rules_flag = True - your = False - other = False - for i in self.__input: - # print(i) - if i == "": - rules_flag = False - if i == "your ticket:": - your = True - continue - if i == "nearby tickets:": - other = True - continue - if rules_flag: - # print(i) - # print(i[: i.index(":")]) - # print(i[i.index(":") + 2 :].split(" or ")) - rules[i[: i.index(":")]] = i[i.index(":") + 2 :].split(" or ") - if your: - # print(i.split()) - yours = i.split(",") - your = False - if other: - others.append(i.split(",")) - - # print(rules) - # discard invalid - # print(f"{len(others)=}") - valid_others = [i for i in others if is_valid(i, rules)] - # print(f"{len(valid_others)=}") - # for k in rules: - # print(f"{k=}") - locations = [] - for p in valid_others[0]: - locations.append([r for r in rules]) - # print(f"{locations=}") - for i in valid_others: - # print(i) - for p, j in enumerate(i): - canbe = [] - # print(j) - for k, v in rules.items(): - # print(f"{k=}, {v=}, {j=}") - for c in range(2): - a = int(v[c].split("-")[0]) - b = int(v[c].split("-")[1]) - # print(f"{j=},{a=},{b=},{a <= int(j) <= b=}") - if a <= int(j) <= b: - canbe.append(k) - # print("cista") - # valid = True - # print(f"{canbe=} in position {p}\n") - new_poss_loc = [] - for l in locations[p]: - # print(l) - if l not in canbe: - ... - # print(f"remove {l}") - else: - new_poss_loc.append(l) - locations[p] = new_poss_loc - # print(f"{locations[p]=}") - # print("\n\n") - # print(f"{locations=}") - iters = 0 - while iters < 100: - for ci, i in enumerate(locations): - # print(f"{i=}, {len(i)=}, {ci=}") - if len(i) == 1: - # print(i) - for cj, j in enumerate(locations): - if ci == cj: - continue - # print(j) - x = [] - for k in j: - # print(f"{k=}, {i[0]=}") - if i[0] == k: - ... - else: - x.append(k) - # - # print(f"{x=}") - locations[cj] = x - iters += 1 - # print(f"{locations=}") - # - # print(f"{len(locations)=}") - # print(f"{len(yours)=}") - # - # print(f"{yours=}") - result = 1 - for c, i in enumerate(locations): - # print(f"{i=}, {c=}") - if "departure" in i[0]: - # print(yours[c]) - result *= int(yours[c]) - return result - - -def is_valid(i, rules): - for j in i: - valid = False - # print(j) - for k, v in rules.items(): - # print(f"{k=}, {v=}, {j=}") - for c in range(2): - a = int(v[c].split("-")[0]) - b = int(v[c].split("-")[1]) - # print(f"{j=},{a=},{b=},{a <= int(j) <= b=}") - if a <= int(j) <= b: - valid = True - if not valid: - return False - return valid diff --git a/y_2020/day18.py b/y_2020/day18.py deleted file mode 100644 index f300a3b..0000000 --- a/y_2020/day18.py +++ /dev/null @@ -1,151 +0,0 @@ -from .common import AoCDay -from .utils import prod - -# GLOBAL_POINTER = 0 - - -def custom_add(a, b): - return a + b - - -def custom_mul(a, b): - return a * b - - -OPS = {"+": custom_add, "*": custom_mul} - - -class Day(AoCDay): - def __init__(self): - super().__init__(18) - - def _preprocess_input(self): - self.__input = [i for i in self._input_data] - - def calc1(self, lst): - # global GLOBAL_POINTER - # print(lst) - # print() - op = None - op_n = 0 - a = 0 - b = 0 - x = [] - ignore = 0 - # breakpoint() - for c, j in enumerate(lst): - # print(f"{j=} in {''.join(lst)}, {ignore=}; {x=}") - if ignore: - if j == ")": - ignore -= 1 - if j == "(": - ignore += 1 - continue - if j == ")": - return a - # continue - if j in OPS: - # print(OPS) - op = j - else: - if op_n == 0: - if j == "(": - ignore += 1 - # breakpoint() - a = self.calc1(lst[c + 1 :]) - else: - a = int(j) - x.append(a) - op_n = 1 - else: - if j == "(": - ignore += 1 - # breakpoint() - b = self.calc1(lst[c + 1 :]) - else: - b = int(j) - if op == "+" or True: - # a = x[-1] - # print(f"{a=}, {b=}") - a = OPS[op](a, b) - # x[-1] = a - else: - x.append(b) - # breakpoint() - # print(f"{x=}") - - return a - - def calc2(self, lst): - # global GLOBAL_POINTER - # print(lst) - # print() - op = None - op_n = 0 - a = 0 - b = 0 - x = [] - ignore = 0 - # breakpoint() - for c, j in enumerate(lst): - # print(f"{j=} in {''.join(lst)}, {ignore=}; {x=}") - if ignore: - if j == ")": - ignore -= 1 - if j == "(": - ignore += 1 - continue - if j == ")": - return prod(x) - # continue - if j in OPS: - # print(OPS) - op = j - else: - if op_n == 0: - if j == "(": - ignore += 1 - # breakpoint() - a = self.calc2(lst[c + 1 :]) - else: - a = int(j) - x.append(a) - op_n = 1 - else: - if j == "(": - ignore += 1 - # breakpoint() - b = self.calc2(lst[c + 1 :]) - else: - b = int(j) - if op == "+": - a = x[-1] - # print(f"{a=}, {b=}") - a = OPS[op](a, b) - x[-1] = a - else: - x.append(b) - # breakpoint() - # print(f"{x=}") - - return prod(x) - - def _calculate_1(self): - # print(self.__input) - result = 0 - for i in self.__input: - express = [k for k in list(i) if k != " "] - # print(f"{express=}") - result += self.calc1(express) - - return result - - def _calculate_2(self): - # print(self.__input) - result = 0 - for i in self.__input: - express = [k for k in list(i) if k != " "] - # print(f"{express=}") - result += self.calc2(express) - - return result diff --git a/y_2020/day19.py b/y_2020/day19.py deleted file mode 100644 index 85ccbef..0000000 --- a/y_2020/day19.py +++ /dev/null @@ -1,49 +0,0 @@ -import re - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(19) - - def _preprocess_input(self): - self.__input = [i for i in self._input_data] - self.__rules = {} - self.__messages = [] - self.get_rules() - self.get_messages() - - def get_rules(self): - for i in self.__input: - if i == "": - break - r = i.split(": ") - self.__rules[int(r[0])] = r[1].replace('"', "").split(" | ") - - def get_messages(self): - found = False - for i in self.__input: - if i == "": - found = True - continue - if found: - self.__messages.append(i) - - def build_regex(self, rule=0): - r = self.__rules[rule] - if len(r) == 1 and r[0].isalpha(): - return r[0] - options = ["".join(self.build_regex(int(j)) for j in i.split(" ")) for i in r] - return "(" + "|".join(options) + ")" - - def _calculate_1(self): - rexp = re.compile("^" + self.build_regex() + "$") - return sum(1 if rexp.match(i) else 0 for i in self.__messages) - - def _calculate_2(self): - R = 6 - self.__rules[8] = [" ".join(["42"] * k) for k in range(1, R)] - self.__rules[11] = [" ".join(["42"] * k + ["31"] * k) for k in range(1, R)] - rexp = re.compile("^" + self.build_regex() + "$") - return sum(1 if rexp.match(i) else 0 for i in self.__messages) diff --git a/y_2020/day2.py b/y_2020/day2.py deleted file mode 100644 index e3a5fc1..0000000 --- a/y_2020/day2.py +++ /dev/null @@ -1,36 +0,0 @@ -import re - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(2) - - def _preprocess_input(self): - self.__password_list = [self.__extract(i) for i in self._input_data] - - def _calculate_1(self): - return sum(self.__valid_1(i) for i in self.__password_list) - - def _calculate_2(self): - return sum(self.__valid_2(i) for i in self.__password_list) - - @staticmethod - def __extract(x): - regex = "([\d]+)-([\d]+) ([\D]): ([\D]*)$" - elements = re.findall(regex, x)[0] - return int(elements[0]), int(elements[1]), elements[2], elements[3] - - @staticmethod - def __valid_1(i): - min, max, char, pwd = i - - c = pwd.count(char) - return c >= min and c <= max - - @staticmethod - def __valid_2(i): - min, max, char, pwd = i - - return (pwd[min - 1] == char) != (pwd[max - 1] == char) diff --git a/y_2020/day3.py b/y_2020/day3.py deleted file mode 100644 index 7024067..0000000 --- a/y_2020/day3.py +++ /dev/null @@ -1,34 +0,0 @@ -from typing import NamedTuple - -from .common import AoCDay -from .utils import prod - - -class Pos(NamedTuple): - x: int - y: int - - -class Day(AoCDay): - def __init__(self): - super().__init__(3) - - def _preprocess_input(self): - return - - def _calculate_1(self, a=3, b=1): - x = self._input_data - - width = len(x[0]) - lenght = len(x) - pos = Pos(0, 0) - c = 0 - while pos.y < lenght: - if x[pos.y][pos.x] == "#": - c += 1 - pos = Pos((pos.x + a) % width, pos.y + b) - return c - - def _calculate_2(self): - rules = [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)] - return prod([self._calculate_1(*a) for a in rules]) diff --git a/y_2020/day4.py b/y_2020/day4.py deleted file mode 100644 index bd11da4..0000000 --- a/y_2020/day4.py +++ /dev/null @@ -1,69 +0,0 @@ -import re -from typing import NamedTuple - -from .common import AoCDay -from .utils import collapse_strings, dict_from_string - -ECL = ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"] - - -class ValidationRule(NamedTuple): - regex: str - validation_func: str - - -def hgt_validation_func(content): - return (content[1] == "cm" and 150 <= int(content[0]) <= 193) or ( - content[1] == "in" and 59 <= int(content[0]) <= 76 - ) - - -FIELDS = { - "byr": ValidationRule("([\d]{4})$", lambda x: 1920 <= int(x) <= 2002), - "iyr": ValidationRule("([\d]{4})$", lambda x: 2010 <= int(x) <= 2020), - "eyr": ValidationRule("([\d]{4})$", lambda x: 2020 <= int(x) <= 2030), - "hgt": ValidationRule("([\d]+)([\D]*)$", hgt_validation_func), - "hcl": ValidationRule("(#[\d|a-f]{6})$", lambda x: True if x else False), - "ecl": ValidationRule("(.*)", lambda x: x in ECL), - "pid": ValidationRule("(^[\d|\w]{9}$)", lambda x: True if x else False) - # "cid" -} - - -class Day(AoCDay): - def __init__(self): - super().__init__(4) - - def _preprocess_input(self): - p_list = [] - for p_string in collapse_strings(self._input_data): - p_dict = {} - for element in p_string.split(" "): - p_dict = {**p_dict, **dict_from_string(element)} - p_list.append(p_dict) - self.__passport_list = p_list - - def _calculate_1(self): - passports = self.__passport_list - return sum( - self.__validate(passport, skip_elements_validation=True) - for passport in passports - ) - - def _calculate_2(self): - passports = self.__passport_list - return sum(self.__validate(passport) for passport in passports) - - @staticmethod - def __validate_element(element: str, value: str) -> bool: - if not (parse := re.findall(FIELDS[element].regex, value)): - return False - return FIELDS[element].validation_func(parse[0]) - - @staticmethod - def __validate(passport: dict, skip_elements_validation: bool = False) -> bool: - return all( - f in passport - and (skip_elements_validation or Day.__validate_element(f, passport[f])) - for f in FIELDS - ) diff --git a/y_2020/day5.py b/y_2020/day5.py deleted file mode 100644 index 7d7204a..0000000 --- a/y_2020/day5.py +++ /dev/null @@ -1,22 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(5) - - def _preprocess_input(self): - self.__decoded_seats = [ - int("".join(["1" if i in ["B", "R"] else "0" for i in encoded_seat]), 2) - for encoded_seat in self._input_data - ] - - def _calculate_1(self): - return max(self.__decoded_seats) - - def _calculate_2(self): - seats = sorted(self.__decoded_seats) - for c, value in enumerate((seats)): - if seats[c] != seats[c + 1] - 1: - return value + 1 - return 0 diff --git a/y_2020/day6.py b/y_2020/day6.py deleted file mode 100644 index f962a52..0000000 --- a/y_2020/day6.py +++ /dev/null @@ -1,33 +0,0 @@ -from collections import Counter -from typing import NamedTuple - -from .common import AoCDay -from .utils import collapse_strings - - -class UserGroup(NamedTuple): - answers: Counter - size: int - - -class Day(AoCDay): - def __init__(self): - super().__init__(6) - - def _preprocess_input(self): - self.__user_groups = [ - UserGroup( - Counter(group_string.replace(" ", "")), group_string.count(" ") + 1 - ) - for group_string in collapse_strings(self._input_data) - ] - - def _calculate_1(self): - return sum(len(group.answers) for group in self.__user_groups) - - def _calculate_2(self): - return sum( - v == group.size - for group in self.__user_groups - for k, v in group.answers.items() - ) diff --git a/y_2020/day8.py b/y_2020/day8.py deleted file mode 100644 index 3d95950..0000000 --- a/y_2020/day8.py +++ /dev/null @@ -1,78 +0,0 @@ -from collections import defaultdict -from typing import NamedTuple - -from .common import AoCDay - - -class Operation(NamedTuple): - acc_action: callable - move_action: callable - - -OPERATIONS = { - "acc": Operation(lambda x: x, lambda x: 1), - "jmp": Operation(lambda x: 0, lambda x: x), - "nop": Operation(lambda x: 0, lambda x: 1), -} - - -class Instruction(NamedTuple): - operation: str - argument: int - - -class Day(AoCDay): - def __init__(self): - super().__init__(8) - - def _preprocess_input(self): - self.__instructions = [ - Instruction(i.split(" ")[0], int((i.split(" "))[1])) - for i in self._input_data - ] - - def _execute(self, local_instructions=None): - if not local_instructions: - local_instructions = self.__instructions - accumulator = 0 - instruction_count = defaultdict(int) - - infinite_loop = False - instr_pointer = 0 - while instr_pointer < len(local_instructions): - if instruction_count[instr_pointer] > 0: - infinite_loop = True - break - instruction_count[instr_pointer] += 1 - - curr_instruction = local_instructions[instr_pointer] - accumulator += OPERATIONS[curr_instruction.operation].acc_action( - curr_instruction.argument - ) - instr_pointer += OPERATIONS[curr_instruction.operation].move_action( - curr_instruction.argument - ) - - if not infinite_loop: - return accumulator, infinite_loop - return accumulator, infinite_loop - - def _calculate_1(self): - execution_result = self._execute() - return execution_result[0] - - def _calculate_2(self): - for attempt in range(len(self.__instructions)): - local_instructions = list(self.__instructions) - local_instructions[attempt] = self.__swap(local_instructions[attempt]) - execution_result = self._execute(local_instructions) - if not execution_result[1]: - return execution_result[0] - - @staticmethod - def __swap(instruction: Instruction): - if instruction.operation == "nop": - return Instruction("jmp", instruction.argument) - if instruction.operation == "jmp": - return Instruction("nop", instruction.argument) - return instruction diff --git a/y_2020/day9.py b/y_2020/day9.py deleted file mode 100644 index 2ecdacb..0000000 --- a/y_2020/day9.py +++ /dev/null @@ -1,39 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self): - super().__init__(9) - - def _preprocess_input(self): - self.__input = [int(i) for i in self._input_data] - - def _calculate_1(self, size=25): - for c, i in enumerate(self.__input[size:]): - temp = self.__input[c : size + c] - correct = False - for j in temp: - for k in temp: - x = j + k - if i == x: - correct = True - break - if correct: - break - if not correct: - break - - self.__problem_1_result = i - return self.__problem_1_result - - def _calculate_2(self, val=None): - if not val: - val = self.__problem_1_result - range = {} - for c, start_range in enumerate(self.__input): - range[start_range] = [] - for j in self.__input[c:]: - range[start_range].append(j) - if sum(range[start_range]) == val: - return start_range + max(range[start_range]) - return 0 diff --git a/y_2020/utils.py b/y_2020/utils.py deleted file mode 100644 index b07f20c..0000000 --- a/y_2020/utils.py +++ /dev/null @@ -1,21 +0,0 @@ -def prod(x): - c = 1 - for i in x: - c *= i - return c - - -def collapse_strings(x: list): - p_list = [[]] - for i in x: - p = p_list[-1] - if len(i) != 0: - p.append(i) - else: - p_list.append([]) - return [" ".join(i) for i in p_list] - - -def dict_from_string(x: str) -> dict: - el_list = x.split(":") - return {el_list[0]: el_list[1]} diff --git a/y_2021/__init__.py b/y_2021/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/y_2021/__main__.py b/y_2021/__main__.py deleted file mode 100644 index 35979d7..0000000 --- a/y_2021/__main__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .common import main - -if __name__ == "__main__": - main() diff --git a/y_2021/common.py b/y_2021/common.py deleted file mode 100644 index 17a44fc..0000000 --- a/y_2021/common.py +++ /dev/null @@ -1,80 +0,0 @@ -import argparse -import importlib -from abc import ABC, abstractmethod -from datetime import datetime - - -class StopWatch: - def __init__(self): - self.__start_time = None - - def start(self): - self.__start_time = datetime.now() - - def lap(self): - return datetime.now() - self.__start_time - - def stop(self): - return datetime.now() - self.__start_time - - -class AoCDay(ABC): - """ - Abstract class Day - """ - - @abstractmethod - def __init__(self, day, test): - self._input_data = load_input(day, test) - self._preprocess_input() - self.__stop_watch = StopWatch() - - @abstractmethod - def _preprocess_input(self): - """ - preprocessing of the input - """ - - @abstractmethod - def _calculate_1(self): - """ - _calculate_1 - """ - - @abstractmethod - def _calculate_2(self): - """ - _calculate_2 - """ - - def solve(self): - self.__stop_watch.start() - print(f"sol 1: {self._calculate_1()} Time taken: {self.__stop_watch.lap()}") - - print(f"sol 2: {self._calculate_2()} Time taken: {self.__stop_watch.stop()}") - - -def load_input(day, test): - file_name = f"y_2021/input_day{day}{'_test'if test else ''}.txt" - with open(file_name) as f: - x = (f.read()).split("\n") - if x[-1] == "": - del x[-1] - return x - - -def main(): - """""" - parser = argparse.ArgumentParser() - parser.add_argument("--day", type=int, help="day as a number") - parser.add_argument("--test", type=int, help="test flag") - args = parser.parse_args() - - module = importlib.import_module(f"y_2021.day{args.day}") - - day = getattr(module, "Day")(test=args.test) - day.solve() - - -if __name__ == "__main__": - main() diff --git a/y_2021/day1.py b/y_2021/day1.py deleted file mode 100644 index 666d0ff..0000000 --- a/y_2021/day1.py +++ /dev/null @@ -1,18 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__input_data = [int(i) for i in self._input_data] - - def _calculate_1(self): - data = self.__input_data - - return sum(data[index] < value for index, value in enumerate(data[1:])) - - def _calculate_2(self): - data = self.__input_data - return sum(data[index] < value for index, value in enumerate(data[3:])) diff --git a/y_2021/day2.py b/y_2021/day2.py deleted file mode 100644 index 7fbba95..0000000 --- a/y_2021/day2.py +++ /dev/null @@ -1,73 +0,0 @@ -from dataclasses import dataclass -from typing import List - -from .common import AoCDay - -COMMANDS_1 = { - "forward": lambda amount, position: Position( - position.horizontal_position + amount, position.depth - ), - "down": lambda amount, position: Position( - position.horizontal_position, position.depth + amount - ), - "up": lambda amount, position: Position( - position.horizontal_position, position.depth - amount - ), -} - -COMMANDS_2 = { - "forward": lambda amount, position: Position( - position.horizontal_position + amount, - position.depth + position.aim * amount, - position.aim, - ), - "down": lambda amount, position: Position( - position.horizontal_position, position.depth, position.aim + amount - ), - "up": lambda amount, position: Position( - position.horizontal_position, position.depth, position.aim - amount - ), -} - - -@dataclass -class Position: - horizontal_position: int - depth: int - aim: int = 0 - - -@dataclass -class Command: - move: int - amount: int - - @staticmethod - def from_instruction(instruction: List): - return Command(instruction[0], int(instruction[1])) - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__input_data = self._input_data - - def _calculate_1(self): - instructions = self.__input_data - position = Position(0, 0) - for instruction in instructions: - command = Command.from_instruction(instruction.split(" ")) - position = COMMANDS_1[command.move](command.amount, position) - - return position.horizontal_position * position.depth - - def _calculate_2(self): - instructions = self.__input_data - position = Position(0, 0, 0) - for instruction in instructions: - command = Command.from_instruction(instruction.split(" ")) - position = COMMANDS_2[command.move](command.amount, position) - - return position.horizontal_position * position.depth diff --git a/y_2021/day3.py b/y_2021/day3.py deleted file mode 100644 index 4c3ce68..0000000 --- a/y_2021/day3.py +++ /dev/null @@ -1,125 +0,0 @@ -from .common import AoCDay -from .utils import decimal_from_binary - - -class Element: - def __init__(self, digit): - self.__digit = int(digit) - self.__valid = True - - def digit(self): - return self.__digit - - def invalidate(self): - self.__valid = False - - def validate(self): - self.__valid = True - - def valid(self): - return self.__valid - - -class Diagnostic: - def __init__(self): - self.__rows = [] - self.__columns = [] - - def __repr__(self): - return "\n".join([str(list(rows)) for rows in self.__rows]) - - def reset(self): - for row in self.__rows: - for element in row: - element.validate() - - def add_row(self, number): - self.__rows.append([]) - for column, digit in enumerate(number): - element = Element(digit) - self.__rows[-1].append(element) - if column >= len(self.__columns): - self.__columns.append([]) - self.__columns[column].append(element) - - def gamma(self): - result = [] - for x in self.__columns: - if sum(int(i.digit()) for i in x) > len(x) // 2: - result.append(1) - else: - result.append(0) - return result - - def epsilon(self): - result = [] - for x in self.__columns: - if sum(int(i.digit()) for i in x) < len(x) // 2: - result.append(1) - else: - result.append(0) - return result - - def oxygen(self): - self.reset() - for c, x in enumerate(self.__columns): - keep = ( - 1 - if sum([int(i.digit()) for i in x if i.valid()]) - >= len([i for i in x if i.valid()]) / 2 - else 0 - ) - for i in self.__rows: - if i[c].digit() != keep: - for j in i: - j.invalidate() - - rows = [] - for c, i in enumerate(self.__rows): - if temp := [x.digit() for x in i if x.valid()]: - rows.append(temp) - if len(rows) == 1: - break - return rows[0] - - def c02(self): - self.reset() - for c, x in enumerate(self.__columns): - keep = ( - 1 - if sum([int(i.digit()) for i in x if i.valid()]) - < len([i for i in x if i.valid()]) / 2 - else 0 - ) - for i in self.__rows: - if i[c].digit() != keep: - for j in i: - j.invalidate() - - rows = [] - for c, i in enumerate(self.__rows): - if temp := [x.digit() for x in i if x.valid()]: - rows.append(temp) - if len(rows) == 1: - break - return rows[0] - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__diagnostic = Diagnostic() - for number in self._input_data: - self.__diagnostic.add_row(number) - - def _calculate_1(self): - return decimal_from_binary(self.__diagnostic.gamma()) * decimal_from_binary( - self.__diagnostic.epsilon() - ) - - def _calculate_2(self): - return decimal_from_binary(self.__diagnostic.oxygen()) * decimal_from_binary( - self.__diagnostic.c02() - ) diff --git a/y_2021/day4.py b/y_2021/day4.py deleted file mode 100644 index c509914..0000000 --- a/y_2021/day4.py +++ /dev/null @@ -1,100 +0,0 @@ -from typing import Dict - -from .common import AoCDay - - -class Element: - def __init__(self, raw_element: str): - self.__element_number = int(raw_element) - self.__called: bool = False - - def call(self): - self.__called = True - - def called(self): - return self.__called - - def __repr__(self): - return str(f"({self.__element_number}; {self.__called})") - - -class Board: - def __init__(self): - self.__rows = [] - self.__columns = [] - self.__elements: Dict[int, Element] = {} - - def __repr__(self): - return "\n".join([str(list(rows)) for rows in self.__rows]) - - def add_row(self, row_board): - self.__rows.append([]) - for column, raw_element in enumerate(row_board.split()): - element = Element(raw_element) - self.__elements[int(raw_element)] = element - self.__rows[-1].append(element) - if column >= len(self.__columns): - self.__columns.append([]) - self.__columns[column].append(element) - - def winner(self): - for i in self.__rows: - if all(j.called() for j in i): - return True - return any(all(j.called() for j in i) for i in self.__columns) - - def flag(self, number: int): - if self.__elements.get(number): - self.__elements.get(number).call() - - def sum_unmarked(self): - return sum(key for key, value in self.__elements.items() if not value.called()) - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__input_data = list(self._input_data) - self.__extracts = self.__input_data[0].split(",") - self.__boards = [] - - for row_board in self.__input_data[1:]: - if row_board == "": - # new board! - board = Board() - self.__boards.append(board) - else: - board.add_row(row_board) - - def _calculate_1(self): - boards = self.__boards - - for i in self.__extracts: - for board in boards: - board.flag(int(i)) - - for board in boards: - if is_winner := board.winner(): - break - if is_winner: - break - - return board.sum_unmarked() * int(i) - - def _calculate_2(self): - boards = self.__boards - - for i in self.__extracts: - for board in boards: - board.flag(int(i)) - - for board in boards: - if board.winner(): - boards.remove(board) - - if len(boards) == 0: - break - - return board.sum_unmarked() * int(i) diff --git a/y_2021/day5.py b/y_2021/day5.py deleted file mode 100644 index d8420e8..0000000 --- a/y_2021/day5.py +++ /dev/null @@ -1,49 +0,0 @@ -from collections import defaultdict - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__input_data = list(self._input_data) - - def _calculate_1(self): - tabs = defaultdict(int) - for move in self.__input_data: - start = move.split(" -> ")[0].split(",") - end = move.split(" -> ")[1].split(",") - if start[0] == end[0]: # x - l = sorted([int(start[1]), int(end[1])]) - for i in range(l[0], l[1] + 1): - tabs[(int(start[0]), i)] += 1 - if start[1] == end[1]: # y - l = sorted([int(start[0]), int(end[0])]) - for i in range(l[0], l[1] + 1): - tabs[(i, int(start[1]))] += 1 - - return sum(i >= 2 for i in tabs.values()) - - def _calculate_2(self): - tabs = defaultdict(int) - for move in self.__input_data: - start = move.split(" -> ")[0].split(",") - end = move.split(" -> ")[1].split(",") - if start[0] == end[0]: # x - l = sorted([int(start[1]), int(end[1])]) - for i in range(l[0], l[1] + 1): - tabs[(int(start[0]), i)] += 1 - elif start[1] == end[1]: # y - l = sorted([int(start[0]), int(end[0])]) - for i in range(l[0], l[1] + 1): - tabs[(i, int(start[1]))] += 1 - elif abs(int(start[0]) - int(end[0])) == abs(int(start[1]) - int(end[1])): - # print("diagonalley") - oriz = -1 if int(start[0]) > int(end[0]) else 1 - vert = -1 if int(start[1]) > int(end[1]) else 1 - for i in range(abs(int(start[0]) - int(end[0])) + 1): - tabs[(int(start[0]) + i * oriz, int(start[1]) + i * vert)] += 1 - - return sum(i >= 2 for i in tabs.values()) diff --git a/y_2021/input_day1_test.txt b/y_2021/input_day1_test.txt deleted file mode 100644 index 167e291..0000000 --- a/y_2021/input_day1_test.txt +++ /dev/null @@ -1,10 +0,0 @@ -199 -200 -208 -210 -200 -207 -240 -269 -260 -263 diff --git a/y_2021/input_day2_test.txt b/y_2021/input_day2_test.txt deleted file mode 100644 index b7172ac..0000000 --- a/y_2021/input_day2_test.txt +++ /dev/null @@ -1,6 +0,0 @@ -forward 5 -down 5 -forward 8 -up 3 -down 8 -forward 2 diff --git a/y_2021/input_day3_test.txt b/y_2021/input_day3_test.txt deleted file mode 100644 index a6366a8..0000000 --- a/y_2021/input_day3_test.txt +++ /dev/null @@ -1,12 +0,0 @@ -00100 -11110 -10110 -10111 -10101 -01111 -00111 -11100 -10000 -11001 -00010 -01010 diff --git a/y_2021/input_day4_test.txt b/y_2021/input_day4_test.txt deleted file mode 100644 index 49d17bc..0000000 --- a/y_2021/input_day4_test.txt +++ /dev/null @@ -1,19 +0,0 @@ -7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 - -22 13 17 11 0 - 8 2 23 4 24 -21 9 14 16 7 - 6 10 3 18 5 - 1 12 20 15 19 - - 3 15 0 2 22 - 9 18 13 17 5 -19 8 7 25 23 -20 11 10 24 4 -14 21 16 12 6 - -14 21 17 24 4 -10 16 15 9 19 -18 8 23 26 20 -22 11 13 6 5 - 2 0 12 3 7 \ No newline at end of file diff --git a/y_2021/input_day5_test.txt b/y_2021/input_day5_test.txt deleted file mode 100644 index b258f68..0000000 --- a/y_2021/input_day5_test.txt +++ /dev/null @@ -1,10 +0,0 @@ -0,9 -> 5,9 -8,0 -> 0,8 -9,4 -> 3,4 -2,2 -> 2,1 -7,0 -> 7,4 -6,4 -> 2,0 -0,9 -> 2,9 -3,4 -> 1,4 -0,0 -> 8,8 -5,5 -> 8,2 diff --git a/y_2021/utils.py b/y_2021/utils.py deleted file mode 100644 index 44b88bc..0000000 --- a/y_2021/utils.py +++ /dev/null @@ -1,8 +0,0 @@ -from typing import List - - -def decimal_from_binary(binary: List): - result = 0 - for digit in binary: - result = result * 2 + digit - return result diff --git a/y_2022/__init__.py b/y_2022/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/y_2022/__main__.py b/y_2022/__main__.py deleted file mode 100644 index 35979d7..0000000 --- a/y_2022/__main__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .common import main - -if __name__ == "__main__": - main() diff --git a/y_2022/day0.py b/y_2022/day0.py deleted file mode 100644 index 2a6ff1b..0000000 --- a/y_2022/day0.py +++ /dev/null @@ -1,21 +0,0 @@ -from common.aoc import AoCDay - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__, test) - - def _preprocess_input(self): - # self.__input_data = [[int(i) for i in chunk] for chunk in self._input_data] - print(f"{self._input_data=}") - self.__input_data = self._input_data[0] - - def _calculate_1(self): - x = self.__input_data - print(f"{x=}") - return 0 - - def _calculate_2(self): - x = self.__input_data - print(f"{x=}") - return 0 diff --git a/y_2022/day1.py b/y_2022/day1.py deleted file mode 100644 index 87459d7..0000000 --- a/y_2022/day1.py +++ /dev/null @@ -1,15 +0,0 @@ -from common.aoc import AoCDay - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__, test) - - def _preprocess_input(self): - self.__input_data = [[int(i) for i in chunk] for chunk in self._input_data] - - def _calculate_1(self): - return max(sum(i) for i in self.__input_data) - - def _calculate_2(self): - return sum(sorted([sum(i) for i in self.__input_data])[-3:]) diff --git a/y_2022/day2.py b/y_2022/day2.py deleted file mode 100644 index 0970b72..0000000 --- a/y_2022/day2.py +++ /dev/null @@ -1,68 +0,0 @@ -from dataclasses import dataclass - -from .common import AoCDay - -OPPONENT_MAP = {"A": "ROCK", "B": "PAPER", "C": "SCISSORS"} -PLAYER_MAP = {"X": "ROCK", "Y": "PAPER", "Z": "SCISSORS"} - -WINNING_PAIRS = [ - # second entry defeats first - ("SCISSORS", "ROCK"), - ("PAPER", "SCISSORS"), - ("ROCK", "PAPER"), -] - - -@dataclass -class RPS_Round: - """Round in Rock Paper Scissors game.""" - - opponent: str - player: str - - shape_values = {"ROCK": 1, "PAPER": 2, "SCISSORS": 3} - - def __outcome(self): # sourcery skip: assign-if-exp, reintroduce-else - if self.opponent == self.player: - return 3 - if (self.opponent, self.player) in WINNING_PAIRS: - return 6 - return 0 - - @property - def score(self): - return self.shape_values[self.player] + self.__outcome() - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__input_data = self._input_data[0] - - def __strategy(self, raw_round): - if raw_round[1] == "Y": # draw - return OPPONENT_MAP[raw_round[0]] - if raw_round[1] == "X": # lose - return {i[1]: i[0] for i in WINNING_PAIRS}[OPPONENT_MAP[raw_round[0]]] - if raw_round[1] == "Z": # win - return {i[0]: i[1] for i in WINNING_PAIRS}[OPPONENT_MAP[raw_round[0]]] - - def _calculate_1(self): - incr = 0 - for i in self.__input_data: - raw_round = i.split(" ") - rps_round = RPS_Round(OPPONENT_MAP[raw_round[0]], PLAYER_MAP[raw_round[1]]) - incr += rps_round.score - return incr - - def _calculate_2(self): - incr = 0 - for i in self.__input_data: - raw_round = i.split(" ") - r = raw_round - response = self.__strategy(raw_round) - rps_round = RPS_Round(OPPONENT_MAP[r[0]], response) - incr += rps_round.score - return incr diff --git a/y_2022/day3.py b/y_2022/day3.py deleted file mode 100644 index fdf4c30..0000000 --- a/y_2022/day3.py +++ /dev/null @@ -1,43 +0,0 @@ -from collections import defaultdict - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__input_data = self._input_data[0] - - def __get_priority( - self, - char: str, - ) -> int: # sourcery skip: assign-if-exp, reintroduce-else - k = ord(char) - if k <= 122 and k >= 97: - return k - 96 - if k <= 90 and k >= 65: - return k - 64 + 26 - return 0 - - def _calculate_1(self): - x = self.__input_data - t = 0 - for i in x: - a = set(i[: len(i) // 2]) - b = set(i[len(i) // 2 :]) - k = list(a & (b))[0] - t += self.__get_priority(k) - return t - - def _calculate_2(self): - x = self.__input_data - d = defaultdict(list) - t = 0 - for c, i in enumerate(x): - d[c // 3].append(i) - for i in d.values(): - k = list(set(i[0]) & set(i[1]) & set(i[2]))[0] - t += self.__get_priority(k) - return t diff --git a/y_2022/day4.py b/y_2022/day4.py deleted file mode 100644 index c1a0867..0000000 --- a/y_2022/day4.py +++ /dev/null @@ -1,35 +0,0 @@ -from typing import Set - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__input_data = self._input_data[0] - - def __create_set(self, raw_range: str) -> Set: - range_start, range_end = raw_range.split("-") - return set(range(int(range_start), int(range_end) + 1)) - - def _calculate_1(self): - def overlaps(s: set, t: set) -> bool: - return s & t in [s, t] - - return sum( - 1 - for i in self.__input_data - if overlaps(*(self.__create_set(k) for k in i.split(","))) - ) - - def _calculate_2(self): - def intersects(s: set, t: set) -> bool: - return s & t != set() - - return sum( - 1 - for i in self.__input_data - if intersects(*(self.__create_set(k) for k in i.split(","))) - ) diff --git a/y_2022/day5.py b/y_2022/day5.py deleted file mode 100644 index 57d449d..0000000 --- a/y_2022/day5.py +++ /dev/null @@ -1,50 +0,0 @@ -from collections import defaultdict -from copy import deepcopy -from typing import Dict, List - -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__parse_stack() - - def __parse_stack(self) -> None: - start = self._input_data[0] - self.__stack: Dict[int, List[str]] = defaultdict(list) - self.__max_rack = sum(1 for _ in start[-1].strip().split(" ")) - for i in range(len(start) - 2, -1, -1): - for j in range(self.__max_rack): - if container := start[i][j * 4 : (j + 1) * 4].strip(): - self.__stack[j + 1].append( - container.replace("[", "").replace("]", ""), - ) - - def __produce_output(self, stack) -> str: - return "".join([stack[i + 1][-1] for i in range(self.__max_rack)]) - - def _calculate_1(self): - moves = self._input_data[1] - local_stack = deepcopy(self.__stack) - for i in moves: - (_, quantity, _, source, _, destination) = i.split(" ") - - for _ in range(int(quantity)): - local_stack[int(destination)].append(local_stack[int(source)].pop()) - return self.__produce_output(local_stack) - - def _calculate_2(self): - moves = self._input_data[1] - local_stack = deepcopy(self.__stack) - for i in moves: - (_, quantity, _, source, _, destination) = i.split(" ") - - t = [] - for _ in range(int(quantity)): - t.insert(0, local_stack[int(source)].pop()) - local_stack[int(destination)].extend(t) - - return self.__produce_output(local_stack) diff --git a/y_2022/day6.py b/y_2022/day6.py deleted file mode 100644 index 274c89f..0000000 --- a/y_2022/day6.py +++ /dev/null @@ -1,26 +0,0 @@ -from .common import AoCDay - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__input_data = self._input_data[0][0] - - def _solution(self, length: int) -> int: - x = self.__input_data - return next( - ( - c + length - for c in range(len(x) - length) - if len(set(x[c : c + length])) == length - ), - 0, - ) - - def _calculate_1(self): - return self._solution(4) - - def _calculate_2(self): - return self._solution(14) diff --git a/y_2022/day7.py b/y_2022/day7.py deleted file mode 100644 index d1d1bc1..0000000 --- a/y_2022/day7.py +++ /dev/null @@ -1,73 +0,0 @@ -from typing import Dict, List, Optional - -from .common import AoCDay - - -class File: - def __init__(self, file: str) -> None: - raw_size, name = file.split() - self.size = int(raw_size) - self.name = name - - -class Folder: - def __init__(self, name: str, parent: Optional["Folder"]) -> None: - self.name = name - self.parent = parent - self.dirs: List["Folder"] = [] - self.files: List[File] = [] - - @property - def full_name(self) -> str: - return f"{self.parent.full_name}#{self.name}" if self.parent else self.name - - @property - def folder_size(self) -> int: - return sum(i.size for i in self.files) - - @property - def nested_size(self) -> int: - return sum(i.total_size for i in self.dirs) - - @property - def total_size(self) -> int: - return self.nested_size + self.folder_size - - -class Day(AoCDay): - def __init__(self, test=0): - super().__init__(__name__.split(".")[1].replace("day", ""), test) - - def _preprocess_input(self): - self.__folders: Dict[str, Folder] = {} - current_folder = None - for i in self._input_data[0]: - if i[0] == "$": - if i[2:4] == "cd": - if ".." in i[5:]: - current_folder = current_folder.parent - else: - f = Folder(i[5:], current_folder) - self.__folders[f.full_name] = f - if current_folder: - current_folder.dirs.append(self.__folders[f.full_name]) - current_folder = f - - elif "dir" not in i[:3]: - current_folder.files.append(File(i)) - - def _calculate_1(self) -> int: - return sum( - i.total_size for i in self.__folders.values() if i.total_size <= 100000 - ) - - def _calculate_2(self) -> int: - needed = abs(70000000 - 30000000 - self.__folders["/"].total_size) - - sorted_folder = dict( - sorted(self.__folders.items(), key=lambda item: item[1].total_size), - ) - return next( - (v.total_size for v in sorted_folder.values() if v.total_size > needed), - 0, - ) diff --git a/y_2022/input_day0_test.txt b/y_2022/input_day0_test.txt deleted file mode 100644 index 2094f91..0000000 --- a/y_2022/input_day0_test.txt +++ /dev/null @@ -1,14 +0,0 @@ -1000 -2000 -3000 - -4000 - -5000 -6000 - -7000 -8000 -9000 - -10000 diff --git a/y_2022/input_day1_test.txt b/y_2022/input_day1_test.txt deleted file mode 100644 index 2094f91..0000000 --- a/y_2022/input_day1_test.txt +++ /dev/null @@ -1,14 +0,0 @@ -1000 -2000 -3000 - -4000 - -5000 -6000 - -7000 -8000 -9000 - -10000 diff --git a/y_2022/input_day2_test.txt b/y_2022/input_day2_test.txt deleted file mode 100644 index db60e36..0000000 --- a/y_2022/input_day2_test.txt +++ /dev/null @@ -1,3 +0,0 @@ -A Y -B X -C Z diff --git a/y_2022/input_day3_test.txt b/y_2022/input_day3_test.txt deleted file mode 100644 index f17e726..0000000 --- a/y_2022/input_day3_test.txt +++ /dev/null @@ -1,6 +0,0 @@ -vJrwpWtwJgWrhcsFMMfFFhFp -jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL -PmmdzqPrVvPwwTWBwg -wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn -ttgJtRGJQctTZtZT -CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/y_2022/input_day4_test.txt b/y_2022/input_day4_test.txt deleted file mode 100644 index 9f9e9cf..0000000 --- a/y_2022/input_day4_test.txt +++ /dev/null @@ -1,6 +0,0 @@ -2-4,6-8 -2-3,4-5 -5-7,7-9 -2-8,3-7 -6-6,4-6 -2-6,4-8 diff --git a/y_2022/input_day5_test.txt b/y_2022/input_day5_test.txt deleted file mode 100644 index 42ef47f..0000000 --- a/y_2022/input_day5_test.txt +++ /dev/null @@ -1,9 +0,0 @@ - [D] -[N] [C] -[Z] [M] [P] - 1 2 3 - -move 1 from 2 to 1 -move 3 from 1 to 3 -move 2 from 2 to 1 -move 1 from 1 to 2 diff --git a/y_2022/input_day6_test.txt b/y_2022/input_day6_test.txt deleted file mode 100644 index 7980a82..0000000 --- a/y_2022/input_day6_test.txt +++ /dev/null @@ -1 +0,0 @@ -mjqjpqmgbljsphdztnvjfqwrcgsmlb diff --git a/y_2022/input_day7_test.txt b/y_2022/input_day7_test.txt deleted file mode 100644 index 09a921e..0000000 --- a/y_2022/input_day7_test.txt +++ /dev/null @@ -1,23 +0,0 @@ -$ cd / -$ ls -dir a -14848514 b.txt -8504156 c.dat -dir d -$ cd a -$ ls -dir e -29116 f -2557 g -62596 h.lst -$ cd e -$ ls -584 i -$ cd .. -$ cd .. -$ cd d -$ ls -4060174 j -8033020 d.log -5626152 d.ext -7214296 k diff --git a/y_2022/submit.p__y b/y_2022/submit.p__y deleted file mode 100644 index 8c384f7..0000000 --- a/y_2022/submit.p__y +++ /dev/null @@ -1,16 +0,0 @@ -import requests - -S = requests.Session() -S.headers["User-Agent"] = "github.com/stegallo" -URL = "https://adventofcode.com/{:d}/day/{:d}/{:s}" -YEAR, DAY = 2022, 2 -S.cookies.set( - "session", -) -part = 1 -answer = 10310 -print("Submitting day {} part {} answer: {}\n", DAY, part, answer) -resp = S.post(URL.format(YEAR, DAY, "answer"), data={"level": part, "answer": answer}) -if resp.status_code != 200: - print("ERROR: response {}, url: {}\n", resp.status_code, resp.url) -print(resp.text.lower()) diff --git a/y_2022/utils.py b/y_2022/utils.py deleted file mode 100644 index dc89403..0000000 --- a/y_2022/utils.py +++ /dev/null @@ -1,8 +0,0 @@ -from typing import List - - -def decimal_from_binary(binary: List) -> int: - result = 0 - for digit in binary: - result = result * 2 + digit - return result