diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0995a96..41c325f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,10 +46,10 @@ repos: hooks: - id: pyupgrade args: [--py37-plus] - # - repo: https://github.com/pre-commit/mirrors-autopep8 - # rev: v2.0.0 - # hooks: - # - id: autopep8 + - repo: https://github.com/pre-commit/mirrors-autopep8 + rev: v2.0.0 + hooks: + - id: autopep8 # - repo: https://github.com/Zac-HD/shed # rev: 0.10.7 # hooks: diff --git a/README.md b/README.md index 3aa9486..6ecd9dc 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ | 03 | [puzzle][201503p]
[✓][201503] | | | | | | | | | 04 | [puzzle][201504p]
[✓][201504] | | | | | | | | | 05 | [puzzle][201505p]
[✓][201505] | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +| 06 | [puzzle][201506p]
[✓][201506] | | | | | | | | +| 07 | [puzzle][201507p]
[✓][201507] | | | | | | | | | 08 | [puzzle][201508p]
[✓][201508] | | | | | | | | [201501]: https://github.com/Stegallo/adventofcode/blob/master/y_2015/day1.py @@ -31,8 +31,6 @@ [201506p]: https://adventofcode.com/2015/day/6 [201507]: https://github.com/Stegallo/adventofcode/blob/master/y_2015/day7.py [201507p]: https://adventofcode.com/2015/day/7 - - [201508]: https://github.com/Stegallo/adventofcode/blob/master/y_2015/day8.py [201508p]: https://adventofcode.com/2015/day/8 diff --git a/common/utilities.py b/common/utilities.py new file mode 100644 index 0000000..0831531 --- /dev/null +++ b/common/utilities.py @@ -0,0 +1,18 @@ +def bitand(x: int, y: int) -> int: + return x & y + + +def bitor(x: int, y: int) -> int: + return x | y + + +def lshift(x: int, y: int) -> int: + return x << y + + +def rshift(x: int, y: int) -> int: + return x >> y + + +def bitnot(x: int) -> int: + return x ^ 65535 diff --git a/requirements/test.txt b/requirements/test.txt index 2c24905..c5a0900 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -3,3 +3,4 @@ flake8 isort pre-commit pytest +pytest-cov diff --git a/tests/common/test_utilites.py b/tests/common/test_utilites.py new file mode 100644 index 0000000..5c01f67 --- /dev/null +++ b/tests/common/test_utilites.py @@ -0,0 +1,9 @@ +from common.utilities import bitand, bitor, lshift, rshift, bitnot + + +def test_bit_ops(): + assert bitand(1, 2) == 0 + assert bitor(1, 2) == 3 + assert lshift(1, 2) == 4 + assert rshift(1, 2) == 0 + assert bitnot(1) == 65534 diff --git a/tests/y_2015/test_2015_day7.py b/tests/y_2015/test_2015_day7.py index 4b722d5..704dfc0 100644 --- a/tests/y_2015/test_2015_day7.py +++ b/tests/y_2015/test_2015_day7.py @@ -2,7 +2,7 @@ from unittest.mock import mock_open, patch -from y_2015.day7 import Day +from y_2015.day7 import Day, Element with patch( "builtins.open", @@ -28,37 +28,16 @@ def test_calculate_1(): def test_calculate_2(): assert day._calculate_2() == 123 -# def test_ingress_resolve(): -# ingress = Ingress('123') -# assert ingress.resolve({}) == Ingress('123') -# -# ingress = Ingress('a') -# assert ingress.resolve({'a': Ingress('1')}) == Ingress('1') -# -# ingress = Ingress('NOT 1') -# assert ingress.resolve({}) == Ingress('65534') -# -# ingress = Ingress('NOT a') -# assert ingress.resolve({'a': Ingress('1')}) == Ingress('65534') -# -# ingress = Ingress('x AND y') -# assert ingress.resolve({'x': Ingress('123'), 'y': Ingress('456')}) == -# Ingress('72') -# -# ingress = Ingress('x OR y') -# assert ingress.resolve({'x': Ingress('123'), 'y': Ingress('456')}) == -# Ingress('507') -# -# ingress = Ingress('x LSHIFT 2') -# assert ingress.resolve({'x': Ingress('123')}) == Ingress('492') -# -# ingress = Ingress('y RSHIFT 2') -# assert ingress.resolve({'y': Ingress('456')}) == Ingress('114') -# -# ingress = Ingress('NOT a') -# assert ingress.resolve({'a': Ingress('NOT b'), 'b': Ingress('1')}) == -# Ingress('1') -# -# ingress = Ingress('NOT a') -# assert ingress.resolve({'a': Ingress('NOT b'), 'b': Ingress('NOT c'), -# 'c': Ingress('NOT d'), 'd':Ingress('x'), 'x': Ingress('1 ')}) == Ingress('1') + +def test_Element_resolve(): + element = Element('123') + assert element.resolve({}) == 123 + + element = Element('a') + assert element.resolve({'a': Element('1')}) == 1 + + element = Element('NOT 1') + assert element.resolve({}) == 65534 + + element = Element('a') + assert element.resolve({'a': Element('b AND b'), 'b': Element('1')}) == 1 diff --git a/y_2015/day7.py b/y_2015/day7.py index ddc03e3..b4dd0f7 100644 --- a/y_2015/day7.py +++ b/y_2015/day7.py @@ -5,24 +5,7 @@ from common.aoc import AoCDay -def bitand(x: int, y: int) -> int: - return x & y - - -def bitor(x: int, y: int) -> int: - return x | y - - -def lshift(x: int, y: int) -> int: - return x << y - - -def rshift(x: int, y: int) -> int: - return x >> y - - -def bitnot(x: int) -> int: - return x ^ 65535 +from common.utilities import bitand, bitor, lshift, rshift, bitnot OPERATORS: Dict[str, Any] = { diff --git a/y_2015/day9.py b/y_2015/day9.py new file mode 100644 index 0000000..2a6ff1b --- /dev/null +++ b/y_2015/day9.py @@ -0,0 +1,21 @@ +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