Skip to content

Commit

Permalink
Merge pull request #197 from Stegallo/2015
Browse files Browse the repository at this point in the history
2015
  • Loading branch information
Stegallo authored Nov 12, 2023
2 parents 168e9cd + c50a51b commit c22f775
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 61 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
| 03 | [puzzle][201503p]</br>[][201503] | | | | | | | |
| 04 | [puzzle][201504p]</br>[][201504] | | | | | | | |
| 05 | [puzzle][201505p]</br>[][201505] | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| 06 | [puzzle][201506p]</br>[][201506] | | | | | | | |
| 07 | [puzzle][201507p]</br>[][201507] | | | | | | | |
| 08 | [puzzle][201508p]</br>[][201508] | | | | | | | |

[201501]: https://github.com/Stegallo/adventofcode/blob/master/y_2015/day1.py
Expand All @@ -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

Expand Down
18 changes: 18 additions & 0 deletions common/utilities.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ flake8
isort
pre-commit
pytest
pytest-cov
9 changes: 9 additions & 0 deletions tests/common/test_utilites.py
Original file line number Diff line number Diff line change
@@ -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
49 changes: 14 additions & 35 deletions tests/y_2015/test_2015_day7.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
19 changes: 1 addition & 18 deletions y_2015/day7.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
21 changes: 21 additions & 0 deletions y_2015/day9.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c22f775

Please sign in to comment.