-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Day18 solution.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""day18 library modules.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
"""Tile Class.""" | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class Tile: | ||
"""Tile for part 1, represents a non-dugout tile.""" | ||
|
||
contents: str = "." | ||
|
||
def __str__(self) -> str: | ||
"""Custom str for easy printing.""" | ||
return self.contents | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class EdgeTile(Tile): | ||
"""Edge tile (``#``).""" | ||
|
||
contents: str = "#" | ||
color: str | ||
|
||
# 38 -> 48 for background | ||
TEXT_WHITE = "\033[38;2;255;255;255m" | ||
|
||
def text_color(self, r: int, g: int, b: int) -> str: | ||
"""Return ansicode color of edge based on input.""" | ||
return f"\033[38;2;{r};{g};{b}m" | ||
|
||
def __str__(self) -> str: | ||
"""Return colored string of ``#`` based on hexcode.""" | ||
r, g, b = [int(self.color[i * 2 : i * 2 + 2], 16) for i in range(3)] | ||
|
||
return f"{self.text_color(r,g,b)}{self.contents}{self.TEXT_WHITE}" | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class HoleTile(Tile): | ||
"""Dug out tile.""" | ||
|
||
contents: str = " " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""day18 tests.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters