Skip to content

Commit

Permalink
Merge pull request #193 from Stegallo/2015_8
Browse files Browse the repository at this point in the history
day8
  • Loading branch information
Stegallo authored Nov 8, 2023
2 parents 9dc5e4f + 091ef71 commit 15117bb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
[201505]: https://github.com/Stegallo/adventofcode/blob/master/y_2015/day5.py
[201505p]: https://adventofcode.com/2015/day/5


[201508]: https://github.com/Stegallo/adventofcode/blob/master/y_2015/day8.py
[201508p]: https://adventofcode.com/2015/day/8

## to run the code

activate the adventofcode virtual environment:
Expand Down
18 changes: 18 additions & 0 deletions tests/y_2015/test_2015_day8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from unittest.mock import mock_open, patch

from y_2015.day8 import Day

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


def test_calculate_1():
day._Day__input_data = ['""', '"abc"', '"aaa\\"aaa"', '"\\x27"']
assert day._calculate_1() == 12


def test_calculate_2():
day._Day__input_data = ['""', '"abc"', '"aaa\\"aaa"', '"\\x27"']
assert day._calculate_2() == 19
17 changes: 17 additions & 0 deletions y_2015/day8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from common.aoc import AoCDay


class Day(AoCDay):
def __init__(self, test=0):
super().__init__(__name__, test)

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

def _calculate_1(self):
string_len = sum(len(x) for x in self.__input_data)
mem_len = sum(len(eval(x)) for x in self.__input_data)
return string_len - mem_len

def _calculate_2(self):
return sum(2 + x.count("\\") + x.count('"') for x in self.__input_data)

0 comments on commit 15117bb

Please sign in to comment.