Skip to main content

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. Uses parser to process the line and yield it.
    • If include_blank_lines is True, blank lines from the file will be included. If False (the default), they will be omitted.
    • If strip is False, leading and trailing spaces and newlines will be included. If True (the default), they will be stripped.
    • parser should be a lambda or function that accepts a string. read_lines will yield the value of parser(line) for each line.
  • read_strings(path: Path, include_blank_lines: bool = False, strip: bool = True) -> Iterator[str]
    • Reads each line from the file at path and yields it.
    • If include_blank_lines is True, blank lines from the file will be included. If False (the default), they will be omitted.
    • If strip is False, leading and trailing spaces and newlines will be included. If True (the default), they will be stripped.
  • read_ints(path: Path) -> Iterator[int]
    • Reads each line from the file at path and yields it as an integer.
  • 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.
  • read_int_groups(path: Path) -> Iterator[list[int]]
    • Reads each line from the file at path and 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.
  • 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.
  • contents should be a list [of any type of object or primitive], containing exactly width * height elements.
  • contents is parsed from left to right, creating a new grid row every width elements.

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, -1 will 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aockit-1.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aockit-1.0.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

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

Hashes for aockit-1.0.2.tar.gz
Algorithm Hash digest
SHA256 4bdc90b9fa77e664c8e3460bb3a4203c5590cf15f3ebe321c89db04534f9663d
MD5 7b48256d3e5ed04414ed05e23190c89a
BLAKE2b-256 696ed22cf1070ed2771f70219b740a2b39c73da2d8cd6bc53121de9df8c83b4b

See more details on using hashes here.

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

Hashes for aockit-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad41f8cef0e396c38035cbe0efafa5433f22a8882a43ab9de1297aa09dad0b5a
MD5 0ce8a138af89eb49506627772ebb998f
BLAKE2b-256 a162c50d7e76d3f6bf5920865bed36edbbcc8afdfc512f7a3016ecf9ceeeddde

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page