Skip to content

Commit

Permalink
2015 d1
Browse files Browse the repository at this point in the history
  • Loading branch information
Stegallo committed Nov 3, 2023
1 parent 29eb056 commit 16d40ab
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 275 deletions.
52 changes: 39 additions & 13 deletions tests/y_2015/test_2015_day1.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
from y_2015.day1 import calculate_1, calculate_2
from __future__ import annotations

from unittest.mock import mock_open, patch

from y_2015.day1 import Day

with patch("builtins.open", mock_open(read_data="0")):
day = Day()


def test_calculate_1():
assert calculate_1("(())") == 0
assert calculate_1("()()") == 0
assert calculate_1("(((") == 3
assert calculate_1("(()(()(") == 3
assert calculate_1("))(((((") == 3
assert calculate_1("())") == -1
assert calculate_1("))(") == -1
assert calculate_1(")))") == -3
assert calculate_1(")())())") == -3
day._Day__input_data = "(())"
assert day._calculate_1() == 0

day._Day__input_data = "((("
assert day._calculate_1() == 3

day._Day__input_data = "(()(()("
assert day._calculate_1() == 3

day._Day__input_data = "))((((("
assert day._calculate_1() == 3

day._Day__input_data = "())"
assert day._calculate_1() == -1

day._Day__input_data = "))("
assert day._calculate_1() == -1

day._Day__input_data = ")))"
assert day._calculate_1() == -3

day._Day__input_data = ")())())"
assert day._calculate_1() == -3


def test_calculate_2():
assert calculate_2(")") == 1
assert calculate_2("()())") == 5
assert calculate_2("(") == -1
day._Day__input_data = ")"
assert day._calculate_2() == 1

day._Day__input_data = "()())"
assert day._calculate_2() == 5

day._Day__input_data = "("
assert day._calculate_2() == -1
11 changes: 0 additions & 11 deletions tests/y_2015/test_2015_day2.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/y_2015/test_2015_day3.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/y_2015/test_2015_day4.py

This file was deleted.

30 changes: 0 additions & 30 deletions tests/y_2015/test_2015_day5.py

This file was deleted.

43 changes: 0 additions & 43 deletions tests/y_2015/test_2015_day6.py

This file was deleted.

143 changes: 0 additions & 143 deletions tests/y_2015/test_2015_day7.py

This file was deleted.

26 changes: 17 additions & 9 deletions y_2015/day1.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from common.aoc import AoCDay

OPERATIONS = {"(": 1, ")": -1}


def calculate_1(i: str) -> int:
return sum(OPERATIONS[x] for x in i)
class Day(AoCDay):
def __init__(self, test=0):
super().__init__(__name__, test)

def _preprocess_input(self):
self.__input_data = self._input_data[0][0]

def _calculate_1(self):
return sum(OPERATIONS[x] for x in self.__input_data)

def calculate_2(i: str) -> int:
result = 0
for j, x in enumerate(i, start=1):
result += OPERATIONS[x]
if result == -1:
return j
return -1
def _calculate_2(self):
result = 0
for j, x in enumerate(self.__input_data, start=1):
result += OPERATIONS[x]
if result == -1:
return j
return -1

0 comments on commit 16d40ab

Please sign in to comment.