Skip to main content

Helper utilities for solving Advent of Code puzzles

Project description

adventofcode

Helper utilities for solving Advent of Code puzzles.

  • No copy-pasting puzzle inputs into files.
  • No need to use low-level file APIs to read your inputs.
  • Performance reports for example inputs and puzzle inputs.
  • Submit the answer immediately when your code returns the result 🏎️

Usage

Install the package

Install the package with pip:

pip install adventofcode

Set your session cookie

Add the adventofcode.com session cookie value to your env:

export AOC_SESSION="..."

Alternatively, you can save your AOC_SESSION="******" value in a .env file.

[!NOTE] Setting AOC_SESSION will allow you to get your personal puzzle output (aoc.get_input()) and submit your answers with aoc.submit_p1() and aoc.submit_p2().

Use a template to solve puzzles

I use the following template to start solving puzzles, see my examples in my repo for 2023.

from adventofcode import AoC


def part1(inp):
    return None


def part2(inp):
    return None


aoc = AoC(part_1=part1, part_2=part2)
inp = """sample input"""
# Run your part1 function with sample input and assert the expected result:
aoc.assert_p1(inp, 42)
# Run your part1 function on puzzle input and submit the answer returned:
aoc.submit_p1()

# Run your part2 function with sample input and assert the expected result:
aoc.assert_p2(inp, 6*7)
# Run your part2 function on puzzle input and submit the answer returned:
aoc.submit_p2()

[!NOTE] All submissions and fetched results are cached locally in the .cache.db file so that we don't spam the AoC servers or resubmit the same answer multiple times.

Or build your workflow using the AoC class

from adventofcode import AoC

aoc = AoC() # defaults to current year and parses the day from the filename (e.g. 01.py will be day 1)

aoc.print_p1() # prints the first part of the puzzle
inp = aoc.get_input() # returns the input as a string
# solve the puzzle here
...
aoc.submit_p1('part 1 answer') # submits the answer to the first part of the puzzle
aoc.print_p2() # prints the second part of the puzzle
# solve the puzzle here
...
aoc.submit_p2('part 2 answer') # submits the answer to the second part of the puzzle

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

adventofcode-23.0b1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

adventofcode-23.0b1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file adventofcode-23.0b1.tar.gz.

File metadata

  • Download URL: adventofcode-23.0b1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for adventofcode-23.0b1.tar.gz
Algorithm Hash digest
SHA256 feb5f81a1d5864c7099fc1c6df87104d74f022ba4aa4d4257f532146fb95100e
MD5 2dd4528a197d48a2ef20fa8126cb1f66
BLAKE2b-256 f86dee5a172ec0618673a88e50129c6d248fe643fade6aa987ccd4f6b4e2b82d

See more details on using hashes here.

File details

Details for the file adventofcode-23.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for adventofcode-23.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 932df17489cccac164c9e80e6b12b7986b6c4ec8fbc59989902392cb024e8a0f
MD5 b9ecb4ee5f04854bbd26ad240b3c70bb
BLAKE2b-256 10b791a3453715a9970b7e6a68bd78999920089fb697dcf1887bf173c62aee06

See more details on using hashes here.

Supported by

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