Skip to content

Commit

Permalink
cleanup AoC 2015.12 solutions #1-9
Browse files Browse the repository at this point in the history
  • Loading branch information
jontsai committed Dec 8, 2022
1 parent 6d20636 commit f0510ee
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 220 deletions.
24 changes: 10 additions & 14 deletions adventofcode/2015/01.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
from utils import (
InputConfig,
ingest,
BaseSolution,
config,
main,
solution,
)


INPUT_FILE = '01.in'
EXPECTED_ANSWERS = (74, 1795, )
config.EXPECTED_ANSWERS = (74, 1795)

config.INPUT_CONFIG.as_oneline = True

def main():
solution = Solution()
answers = (solution.solve1(), solution.solve2(), )
print(answers)
assert(answers == EXPECTED_ANSWERS)


class Solution:
def __init__(self):
data = ingest(INPUT_FILE, InputConfig(as_oneline=True))
self.instructions = data
@solution
class Solution(BaseSolution):
def process_data(self):
self.instructions = self.data

def solve1(self):
floor = 0
Expand Down
39 changes: 19 additions & 20 deletions adventofcode/2015/02.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from utils import ingest
from utils import (
BaseSolution,
config,
main,
solution,
)


INPUT_FILE = '02.in'
EXPECTED_ANSWERS = (1588178, 3783758, )
config.EXPECTED_ANSWERS = (1588178, 3783758)


def main():
solution = Solution()
answers = (solution.solve1(), solution.solve2(), )
print(answers)
assert(answers == EXPECTED_ANSWERS)


class Solution:
def __init__(self):
self.data = ingest(INPUT_FILE)
@solution
class Solution(BaseSolution):
def process_data(self):
self.presents = [Present(dimensions) for dimensions in self.data]

def solve1(self):
Expand All @@ -33,7 +30,7 @@ def __init__(self, dimensions):
@property
def surface_area(self):
l, w, h = self.l, self.w, self.h
area = 2*l*w + 2*w*h + 2*h*l
area = 2 * l * w + 2 * w * h + 2 * h * l
return area

@property
Expand All @@ -50,11 +47,13 @@ def lh_area(self):

@property
def smallest_side_area(self):
return min([
self.lw_area,
self.wh_area,
self.lh_area,
])
return min(
[
self.lw_area,
self.wh_area,
self.lh_area,
]
)

@property
def wrapping_paper_area(self):
Expand All @@ -63,7 +62,7 @@ def wrapping_paper_area(self):
@property
def smallest_perimeter(self):
a, b, c = sorted([self.l, self.w, self.h])
return 2*a + 2*b
return 2 * a + 2 * b

@property
def volume(self):
Expand Down
24 changes: 10 additions & 14 deletions adventofcode/2015/03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@
from collections import defaultdict

from utils import (
InputConfig,
ingest,
BaseSolution,
config,
main,
solution,
)


INPUT_FILE = '03.in'
EXPECTED_ANSWERS = (2565, 2639, )
config.EXPECTED_ANSWERS = (2565, 2639)

config.INPUT_CONFIG.as_oneline = True

def main():
solution = Solution()
answers = (solution.solve1(), solution.solve2(), )
print(answers)
assert(answers == EXPECTED_ANSWERS)


class Solution:
def __init__(self):
data = ingest(INPUT_FILE, InputConfig(as_oneline=True))
self.directions = data
@solution
class Solution(BaseSolution):
def process_data(self):
self.directions = self.data
self.delivery_map = DeliveryMap(self.directions)

def solve1(self):
Expand Down
28 changes: 11 additions & 17 deletions adventofcode/2015/04.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@
import hashlib

from utils import (
InputConfig,
ingest,
BaseSolution,
config,
main,
solution,
)


INPUT_FILE = '04.in'
EXPECTED_ANSWERS = (254575, 1038736, )
config.EXPECTED_ANSWERS = (254575, 1038736)
config.TEST_CASES = {'': (609043, 6742839)}

# INPUT_FILE = '4.test.in'
# EXPECTED_ANSWERS = (609043, 6742839, )
config.INPUT_CONFIG.as_oneline = True


def main():
solution = Solution()
answers = (solution.solve1(), solution.solve2(), )
print(answers)
assert(answers == EXPECTED_ANSWERS)


class Solution:
def __init__(self):
data = ingest(INPUT_FILE, InputConfig(as_oneline=True))
self.key = data
@solution
class Solution(BaseSolution):
def process_data(self):
self.key = self.data

def solve1(self):
n = 1
Expand Down
45 changes: 18 additions & 27 deletions adventofcode/2015/05.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
from utils import ingest
from utils import (
BaseSolution,
config,
main,
solution,
)


INPUT_FILE = '05.in'
EXPECTED_ANSWERS = (255, 55, )
config.EXPECTED_ANSWERS = (255, 55)
config.TEST_CASES = {
'': (2, 2),
}

# INPUT_FILE = '05.test.in'
# EXPECTED_ANSWERS = (2, 2, )


def main():
solution = Solution()
answers = (solution.solve1(), solution.solve2(), )
print(answers)
assert(answers == EXPECTED_ANSWERS)


class Solution:
def __init__(self):
self.data = ingest(INPUT_FILE)
@solution
class Solution(BaseSolution):
def process_data(self):
self.strings = [NaughtyOrNice(s) for s in self.data]

def solve1(self):
Expand Down Expand Up @@ -53,10 +50,7 @@ def contains_naughty(self):

@property
def contains_3_vowels(self):
vowels = [
c for c in self.s
if c in self.VOWELS
]
vowels = [c for c in self.s if c in self.VOWELS]
has_3 = len(vowels) >= 3
return has_3

Expand Down Expand Up @@ -88,9 +82,9 @@ def has_distinct_repeating_pair(self):
has_repeat = False

for i in range(len(s) - 4 + 1):
pair = s[i:i + 2]
for j in range(i+2, len(s) - 2 + 1):
pair2 = s[j:j + 2]
pair = s[i : i + 2]
for j in range(i + 2, len(s) - 2 + 1):
pair2 = s[j : j + 2]
if pair == pair2:
has_repeat = True
break
Expand All @@ -115,10 +109,7 @@ def has_3_palindrome(self):

@property
def is_nice2(self):
is_nice = (
self.has_distinct_repeating_pair
and self.has_3_palindrome
)
is_nice = self.has_distinct_repeating_pair and self.has_3_palindrome

return is_nice

Expand Down
52 changes: 28 additions & 24 deletions adventofcode/2015/06.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
# Python Standard Library Imports
import re

from utils import ingest
from utils import (
BaseSolution,
config,
main,
solution,
)


INPUT_FILE = '06.in'
EXPECTED_ANSWERS = (543903, 14687245, )
config.EXPECTED_ANSWERS = (543903, 14687245)
config.TEST_CASES = {
'': (1_000_000 - 1_000 - 4, 3001997),
}

# INPUT_FILE = '06.test.in'
# EXPECTED_ANSWERS = (1000000 - (1000000 - 1000 - 4), 3001997, )


def main():
solution = Solution()
answers = (solution.solve1(), solution.solve2(), )
print(answers)
assert(answers == EXPECTED_ANSWERS)


class Solution:
def __init__(self):
data = ingest(INPUT_FILE)
@solution
class Solution(BaseSolution):
def process_data(self):
data = self.data
self.instructions = [Instruction(instruction) for instruction in data]
self.light_show = LightShow(self.instructions)

Expand All @@ -36,7 +34,9 @@ def solve2(self):


class Instruction:
REGEXP = re.compile(r'^(?P<operation>(turn on)|(turn off)|(toggle)) (?P<x1>\d+),(?P<y1>\d+) through (?P<x2>\d+),(?P<y2>\d+)$')
REGEXP = re.compile(
r'^(?P<operation>(turn on)|(turn off)|(toggle)) (?P<x1>\d+),(?P<y1>\d+) through (?P<x2>\d+),(?P<y2>\d+)$'
)

def __init__(self, instruction):
self.instruction = instruction
Expand All @@ -57,15 +57,19 @@ def __init__(self, instructions):
self.instructions = instructions

self.lights = [
[False, ] * 1000
for x
in range(1000)
[
False,
]
* 1000
for x in range(1000)
]

self.lights2 = [
[0, ] * 1000
for x
in range(1000)
[
0,
]
* 1000
for x in range(1000)
]

def run(self):
Expand All @@ -86,7 +90,7 @@ def run(self):
elif operation == 'turn off':
lights[i][j] = False
elif operation == 'toggle':
lights[i][j] = not(lights[i][j])
lights[i][j] = not (lights[i][j])
else:
raise Exception('Illegal operation: %s' % operation)

Expand Down
2 changes: 0 additions & 2 deletions adventofcode/2015/06.test.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
turn on 0,0 through 999,999
toggle 0,0 through 999,0
turn off 499,499 through 500,500
turn on 0,0 through 0,0
toggle 0,0 through 999,999
Loading

0 comments on commit f0510ee

Please sign in to comment.