A set of common utilities for completing the Advent of Code.
Project description
AoCKit
A set of common utilities for completing the Advent of Code.
Input Parsing (aockit.inputs)
Utility functions for reading puzzle input from a file.
read_lines(path: Path, parser: Callable[[str], T], include_blank_lines: bool = False, strip: bool = True) -> Iterator[T]- Reads each line from the file at
path. Usesparserto process the line and yield it. - If
include_blank_linesis True, blank lines from the file will be included. If False (the default), they will be omitted. - If
stripis False, leading and trailing spaces and newlines will be included. If True (the default), they will be stripped. parsershould be a lambda or function that accepts a string.read_lineswill yield the value ofparser(line)for each line.
- Reads each line from the file at
read_strings(path: Path, include_blank_lines: bool = False, strip: bool = True) -> Iterator[str]- Reads each line from the file at
pathand yields it. - If
include_blank_linesis True, blank lines from the file will be included. If False (the default), they will be omitted. - If
stripis False, leading and trailing spaces and newlines will be included. If True (the default), they will be stripped.
- Reads each line from the file at
read_ints(path: Path) -> Iterator[int]- Reads each line from the file at
pathand yields it as an integer.
- Reads each line from the file at
read_string_groups(path: Path) -> Iterator[list[str]]- Reads each line from the file at
path. - Lines are organized into groups, separated by blank lines in the file.
- Each group is yielded as a list of strings.
- Reads each line from the file at
read_int_groups(path: Path) -> Iterator[list[int]]- Reads each line from the file at
pathand parses it as an integer. - Lines are organized into groups, separated by blank lines in the file.
- Each group is yielded as a list of integers.
- Reads each line from the file at
read_char_grid(path: Path) -> Grid[str]- Reads a grid of characters from the path.
- See Grid docs for more info.
read_int_grid(path: Path) -> Grid[int]- Reads a grid of integers from the path.
- See Grid docs for more info.
Grid Data Structure (aockit.grid)
A two-dimensional grid, which can store any data type. Can be indexed or iterated easily by rows or columns. Extremely useful for many puzzles.
Constructor
Grid(height: int, width: int, content: list[T])
- Constructs a grid object with the given height, width, and contents.
contentsshould be a list [of any type of object or primitive], containing exactlywidth * heightelements.contentsis parsed from left to right, creating a new grid row everywidthelements.
Accessing elements
g.get(row, col) or g[row, col]
- Retrieves the element at the given row and column.
- Rows and columns are zero-indexed, starting at the top left.
- Negative indices work the same as with Python lists (
-1, -1will get you the bottom right element).
Setting elements
g.set(row, col, value) or g[row, col] = value
- Sets the element at the given row and column.
- Indexing works the same as above.
Iterating over rows and columns
g.col(col) or g.row(row)
- Returns an iterator for the values in the given row or column.
- Columns are traversed top to bottom, rows from left to right.
- Row and column indices start at 0, and negative indices work as above.
g.col_indexed(col) or g.row_indexed(row)
- Iterates over the given row or column, with the row and column indices included.
- Each iterator value is a tuple consisting of
(row, col, value).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aockit-1.0.2.tar.gz.
File metadata
- Download URL: aockit-1.0.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bdc90b9fa77e664c8e3460bb3a4203c5590cf15f3ebe321c89db04534f9663d
|
|
| MD5 |
7b48256d3e5ed04414ed05e23190c89a
|
|
| BLAKE2b-256 |
696ed22cf1070ed2771f70219b740a2b39c73da2d8cd6bc53121de9df8c83b4b
|
File details
Details for the file aockit-1.0.2-py3-none-any.whl.
File metadata
- Download URL: aockit-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad41f8cef0e396c38035cbe0efafa5433f22a8882a43ab9de1297aa09dad0b5a
|
|
| MD5 |
0ce8a138af89eb49506627772ebb998f
|
|
| BLAKE2b-256 |
a162c50d7e76d3f6bf5920865bed36edbbcc8afdfc512f7a3016ecf9ceeeddde
|