Advent of Code helpers
Advent of Code helper functions
from aoc.helpers import output, read_input_from_file, input_lines
from aoc import template
Setup Guide
Install with pip
pip install advent-of-code-helpers
Helper Usage
read_input_from_file reads the data as a single line from a file
from aoc.helpers import read_input_from_file
read_input_from_file('path/to/input_data')
input_lines returns a list of strings from the string input
from aoc.helpers import input_lines
input_lines('single\nstring\ninput')
output prints the result to console and writes to an output file if an output directory is provided
from aoc.helpers import output
output('result', part(int), day(int), year(int), output_dir(str), file_prefix(str))
Template Usage
You can specify data from a file using the data(input) function.
You can specify an output directory for output using the output(output) function. If left empty, it will still print to screen, but will not write the result to a file. If given an output directory, the results will be appended to the file so you can easily go back and look at previous results.
Examples
from aoc import template
class Part1(template.Part1):
def solve(self):
# Read input
lines = input_lines(self.input())
# Do some work here
# Sample output
result = ','.join(lines)
return result
def main():
output_dir = '../out'
test_data = os.path.join(os.path.dirname(__file__),
'resources/test_input.txt')
Part1(1, 2018).data(test_data).output(output_dir)
data = os.path.join(os.path.dirname(__file__), 'resources/input.txt')
Part1(1, 2018).data(data).output(output_dir)
if __name__ == "__main__":
main()
More usage in the example.
Template Usage with Other Libraries
If you want to use your own input reader or a library like advent-of-code-data, you can override the input method.
Examples
from aoc import template
from aoc.helpers import input_lines
from aocd import get_data
class Part1(template.Part1):
def input(self):
if self.input_file:
return super().input()
else:
return get_data(day=self.day, year=self.year)
def solve(self):
# Read input
lines = input_lines(self.input())
# Do some work here
# Sample output
result = ','.join(lines)
return result
def main():
Part1(1, 2018).output('../out')
if __name__ == "__main__":
main()
Metadata
Release files for advent-of-code-helpers 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| advent-of-code-helpers-0.1.1.tar.gz | 8.8 kB | Without provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| advent_of_code_helpers-0.1.1-py3.8.egg | Legacy Egg format | - | - | Details |
| advent_of_code_helpers-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.5 kB
Release files / advent-of-code-helpers-0.1.1.tar.gz
| Download URL | advent-of-code-helpers-0.1.1.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f96ddac72a02308d303ddb2ab7c35d46e2a5725ba75e78678fb67c84282fcdf1
|
|
BLAKE2b-256 checksum How to use checksums |
0a61fa5a3886dc78074f4b3837369f442d19eb0463a9a650a4841fc0d9eaec1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
|
Release files / advent_of_code_helpers-0.1.1-py3.8.egg
| Download URL | advent_of_code_helpers-0.1.1-py3.8.egg |
|---|---|
| Size | 3.9 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
84302d7da72bb1449bdeacc2a0260273a1943722ed0f5fae3d6447a6bfe7deb7
|
|
BLAKE2b-256 checksum How to use checksums |
63fec38998f19175cd648a6150f4135cdcaa7ddfc4380337c89bc81a3dc290a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
|
Release files / advent_of_code_helpers-0.1.1-py3-none-any.whl
| Download URL | advent_of_code_helpers-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e237b58088a23df4d82b185bdf44c501abe63b463c2bcb21b14d8e2c937a86b6
|
|
BLAKE2b-256 checksum How to use checksums |
17ea2da8f70792fd8412a46e34bed9f4c6af26860f6988d457e18933fffe536b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
|
Security for advent-of-code-helpers 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.