Advent of Code helper functions
Project description
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()
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
Built Distributions
File details
Details for the file advent-of-code-helpers-0.1.1.tar.gz
.
File metadata
- Download URL: advent-of-code-helpers-0.1.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f96ddac72a02308d303ddb2ab7c35d46e2a5725ba75e78678fb67c84282fcdf1 |
|
MD5 | 8a191684b4b32c3d0138b614e7d6cacb |
|
BLAKE2b-256 | 0a61fa5a3886dc78074f4b3837369f442d19eb0463a9a650a4841fc0d9eaec1b |
File details
Details for the file advent_of_code_helpers-0.1.1-py3.8.egg
.
File metadata
- Download URL: advent_of_code_helpers-0.1.1-py3.8.egg
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84302d7da72bb1449bdeacc2a0260273a1943722ed0f5fae3d6447a6bfe7deb7 |
|
MD5 | 53c92856900d27e92d0bced759d8000a |
|
BLAKE2b-256 | 63fec38998f19175cd648a6150f4135cdcaa7ddfc4380337c89bc81a3dc290a7 |
File details
Details for the file advent_of_code_helpers-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: advent_of_code_helpers-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e237b58088a23df4d82b185bdf44c501abe63b463c2bcb21b14d8e2c937a86b6 |
|
MD5 | 9d401bcfceb444c083a9995a1c736485 |
|
BLAKE2b-256 | 17ea2da8f70792fd8412a46e34bed9f4c6af26860f6988d457e18933fffe536b |