Skip to main content

Cool set of tools for working with Advent of Code challenges

Project description

advent-tools

Python interface to conveniently download and interact with advent data with a high-level-wrapper.

Installation

A Virtual Environment is strongly recommended to install the library

# Linux/macOS
python3 -m pip install -U advent-tools

# Windows
py -3 -m pip install -U advent-tools

Quickstart

First we need to get the session cookie (🍪), in order to do that

  1. Open your broswer's Devtools (Chrome / Firefox guide)
  2. Head on over to Application tab, then to Cookies
  3. Find and copy session cookie value "Steps to get session cookie"
  4. set AOC_SESSION=<session-cookie-value> environment variable (make sure terminal restart doesn't reset the value)
    OR
    Enter the following command in your terminal which will create an .env file storing your session cookie.
# Same for all Windows, Linux and macOS
echo AOC_SESSION=<session-cookie-value> > .env
# Make sure to replace <session-cookie-value> with your cookie value

Make sure version control system ignores your token container in case you are using one, cause your token is sensitive and can be used for log-ins.


Usage

year and day can be given as kwargs when subclassing advent.Advent or can be provided using it's __getitem__ behaviour like Advent[year:day]

from advent import Advent


class Solution(Advent, year=2020, day=3):
    def __init__(self, data: str) -> None:
        self.data = ...

    def part_1(self):
        ...

    def part_2(self):
        ...

Example 1:

from advent import Advent


class Solution(Advent, year=2022, day=2):
    PLAY = {"A": ["Z", "X", "Y"], "B": ["X", "Y", "Z"], "C": ["Y", "Z", "X"]}

    def __init__(self, data: str) -> None:
        self.data = [line.split() for line in data.splitlines()]

    def part_1(self):
        return sum(self.PLAY[oppo].index(me) * 3 + ord(me) - 87 for oppo, me in self.data)

    def part_2(self):
        return sum((fate := ord(res) - 88) * 3 + ord(self.PLAY[oppo][fate]) - 87 for oppo, res in self.data)

Example 2:

from heapq import nlargest
from advent import Advent

class Solution(Advent[2022:1]):
    def __init__(self, data: str) -> None:
        self.max, *self.top = nlargest(3, [sum(map(int, chunk.split())) for chunk in data.split("\n\n")])

    def part_1(self):
        return self.max

    def part_2(self):
        return self.max + sum(self.top)

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

advent_tools-1.0.0b1.tar.gz (374.3 kB view details)

Uploaded Source

Built Distribution

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

advent_tools-1.0.0b1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file advent_tools-1.0.0b1.tar.gz.

File metadata

  • Download URL: advent_tools-1.0.0b1.tar.gz
  • Upload date:
  • Size: 374.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for advent_tools-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 de2e8c3509a9bd73e4d516eb5a2b5bd618054860e5c880a90e30566a7d5e9879
MD5 86631722e286ae0552f61d68322a33fc
BLAKE2b-256 073578b6d5178c47b4e58244b221fc1139ba3aec631268441639a7e4dfced1c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for advent_tools-1.0.0b1.tar.gz:

Publisher: publish.yml on Achxy/advent-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file advent_tools-1.0.0b1-py3-none-any.whl.

File metadata

  • Download URL: advent_tools-1.0.0b1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for advent_tools-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a46ea7517832a8226506d13be50eb587f651308e6525003a6f1285ef3af89f3
MD5 c66ed3c9e9113e00a0495045ae28a40d
BLAKE2b-256 c1fe4fc3249a280a8e473d28c176e08ef6245b6a6090235f1335cbb0dc7ad515

See more details on using hashes here.

Provenance

The following attestation bundles were made for advent_tools-1.0.0b1-py3-none-any.whl:

Publisher: publish.yml on Achxy/advent-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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