Skip to content

Commit

Permalink
Less aggressive formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
micknudsen committed Aug 6, 2024
1 parent 3d8101b commit f86ec62
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 74 deletions.
10 changes: 2 additions & 8 deletions 2015/01/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@
class InvalidInstructionError(Exception):
"""Raised when Santa receives an invalid instruction."""

def __init__(
self,
instruction: str,
) -> None:
def __init__(self, instruction: str) -> None:
self.message = f"Invalid instruction: {instruction}"
super().__init__(self.message)


class FloorNeverReachedError(Exception):
"""Raised when Santa never reaches the specified floor."""

def __init__(
self,
floor: int,
) -> None:
def __init__(self, floor: int) -> None:
self.message = f"Never reached floor: {floor}"
super().__init__(self.message)

Expand Down
12 changes: 2 additions & 10 deletions 2015/02/code.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import unittest


def paper_needed(
length: int,
width: int,
height: int,
) -> int:
def paper_needed(length: int, width: int, height: int) -> int:
"""To wrap a box, the elves need to cover the surface area, and
for some reason they also need a little extra paper with an area
equal to the area of the smallest side of the box."""
Expand All @@ -18,11 +14,7 @@ def paper_needed(
return 2 * sum(areas) + min(areas)


def ribbon_needed(
length: int,
width: int,
height: int,
) -> int:
def ribbon_needed(length: int, width: int, height: int) -> int:
"""To wrap a box, the elves need a bow made out of ribbon. The
required length is the smallest perimeter of any one face. An
additional amount of ribbon of length equal to the volume of
Expand Down
9 changes: 2 additions & 7 deletions 2015/03/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
class InvalidDirectionError(Exception):
"""Raised when Santa is asked to go in a invalid direction."""

def __init__(
self,
direction: str,
) -> None:
def __init__(self, direction: str) -> None:
self.message = f"Invalid direction: {direction}"
super().__init__(self.message)

Expand All @@ -31,9 +28,7 @@ def __hash__(self) -> int:
)


def houses_visited(
directions: Iterable[str],
) -> Set[House]:
def houses_visited(directions: Iterable[str]) -> Set[House]:
"""Santa visits houses starting at (0, 0) based on directions. He
can either go north ("^"), south ("v"), east (">"), or west ("<").
He will refuse to go in any other direction, and he will raise an
Expand Down
5 changes: 1 addition & 4 deletions 2015/04/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import unittest


def mine_coin(
key: str,
hardness: int,
) -> int:
def mine_coin(key: str, hardness: int) -> int:
"""Given a key string, mining an AdventCoin requires finding a
number (not starting with zero), such than the MD5 hash of the
key followed by the number starts with a given number of zeros."""
Expand Down
8 changes: 2 additions & 6 deletions 2015/05/code.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import unittest


def is_nice_first_attempt(
message: str,
) -> bool:
def is_nice_first_attempt(message: str) -> bool:
"""Santa has come up with a very sophisticated algorithm for determining
whether a string is naughty or nice."""

Expand Down Expand Up @@ -31,9 +29,7 @@ def is_nice_first_attempt(
return True


def is_nice_second_attempt(
message: str,
) -> bool:
def is_nice_second_attempt(message: str) -> bool:
"""Realizing that the first algorithm was no good, Santa devises
a completely new algorithm."""

Expand Down
5 changes: 1 addition & 4 deletions 2015/06/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
class InvalidActionError(Exception):
"""Raised when the grid is asked to perform an invalid action."""

def __init__(
self,
action: str,
) -> None:
def __init__(self, action: str) -> None:
self.message = f"Invalid action: {action}"
super().__init__(self.message)

Expand Down
15 changes: 3 additions & 12 deletions 2015/07/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
class ComputeError(Exception):
"""Raised when the circuit is unable to compute the value of a wire."""

def __init__(
self,
wire: str,
) -> None:
def __init__(self, wire: str) -> None:
self.message = f"Unable to compute wire: {wire}"
super().__init__(self.message)

Expand All @@ -20,10 +17,7 @@ class Circuit:
"""Class representing a circuit comprising wires and gates. The
value of a wire can be computed by following a set of instructions."""

def __init__(
self,
instructions: Iterable[str],
) -> None:
def __init__(self, instructions: Iterable[str]) -> None:
self.connections: dict[str, str] = dict(
map(
lambda x: x.split(" -> ")[::-1],
Expand All @@ -32,10 +26,7 @@ def __init__(
)

@functools.cache
def compute(
self,
wire: str,
) -> int:
def compute(self, wire: str) -> int:
"""Compute the value of a wire using recursion. Cache all
computed values to speed up the process."""

Expand Down
8 changes: 2 additions & 6 deletions 2015/08/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
import unittest


def overhead(
string: str,
) -> int:
def overhead(string: str) -> int:
"""Every line on Santa's list is enclosed by double quotes and
maybe contain some escaped characters. This function computes the
overhead memory used for storing all this things compared to the
bare string literal itself."""
return len(string) - len(ast.literal_eval(string))


def increase(
string: str,
) -> int:
def increase(string: str) -> int:
"""Every entry on Santa's list must now be further encoded. This
means enclosing the string literal in double quotes and escaping
quotes and backslashes inside the string itself. This function
Expand Down
16 changes: 3 additions & 13 deletions 2015/09/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ class Map:
distances between them stored in a symmetric matrix implemented
as a dictionary of dictionaries."""

def __init__(
self,
distances: Dict[str, Dict[str, int]],
) -> None:
def __init__(self, distances: Dict[str, Dict[str, int]]) -> None:
self._distances = distances

@classmethod
def init_from_strings(
cls,
strings: Iterable[str],
) -> "Map":
def init_from_strings(cls, strings: Iterable[str]) -> "Map":
"""Convenient way to initializa a Map instance from a
list of strings as given in the puzzle input."""
distances: Dict[str, Dict[str, int]] = defaultdict(dict)
Expand All @@ -32,11 +26,7 @@ def init_from_strings(
distances=distances,
)

def distance(
self,
source: str,
destination: str,
) -> int:
def distance(self, source: str, destination: str) -> int:
"""Returns the distance between two cities."""
return self._distances[source][destination]

Expand Down
6 changes: 2 additions & 4 deletions 2015/12/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
from typing import Optional


def total(
document: str,
ignore_red: Optional[bool] = False,
) -> int:
def total(document: str, ignore_red: Optional[bool] = False) -> int:
"""Calculate the sum of all numbers in a JSON document. Optionally ignore all
dictionary objects (and all their children) if they the contain the value 'red'."""

match data := json.loads(document):
case int():
return data
Expand Down

0 comments on commit f86ec62

Please sign in to comment.