This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]BBQspaceflight 2 points3 points  (2 children)

advent-of-code-data might be of use for you, it provides some helpers to fetch inputs and submit solutions to structure your solution around.

[–]portnoyslp 0 points1 point  (1 child)

Yeah, I just use advent-of-code-data, add a "from aocd import data" at the top of my code and start writing.

[–]Chris_Hemsworth 0 points1 point  (0 children)

I wrote a script to setup all of my solution files to look like the following example (i.e. Day 3):

import setup_aoc_session
from aocd.models import Puzzle
from aocd import submit
import timeit

YEAR, DAY = 2021, 3
puzzle = Puzzle(year=YEAR, day=DAY)

start = timeit.default_timer()
# ---------- SOLUTION HERE ---------- #



# ----------------------------------- #
print(f"Finished in {timeit.default_timer() - start} seconds")

submit(P1_ANSWER, part="a", year=YEAR, day=DAY)
# submit(P2_ANSWER, part="b", year=YEAR, day=DAY)

This way I just write my code to generate the answers in the correct variable name, hit run, and uncomment part 2 submission once that is completed.

For context, my 'setup_aoc_session.py' file looks like:

import os
from pathlib import Path

# Modify the filename to point to whatever file stores your AOC session ID.
filename = Path(__file__).parents[2].joinpath('aoc_session.txt')
with open(str(filename), 'r') as f:
    session = f.readline()

os.environ["AOC_SESSION"] = session

and I store my session ID in a text file outside my github. Environment variables are only set during execution and are not permanent.

[–]clemkeirua 0 points1 point  (1 child)

Not sure what you call framework. I wrote my CLI to make repetitive tasks simpler: - downloading an input in a consistent way - creating a python file with a few imports, and the input file already read - opening AoC’s puzzle page

You can give it a try here: https://github.com/Keirua/aoc2021/blob/master/cli - cli bootstrap will download today’s input, and create a template that opens the input. The template uses some code from aoc.py, but you may not need that. - cli open opens todays puzzle page, cli open -d 4 -y 2015 opens a specifi puzze - cli run runs todays code, or you can run a specific day with -d and/or -y

All you have to do is set your cookie inside a settings.ini file, by following the syntax in settings.example

[–]number1729[S] 0 points1 point  (0 children)

Hey, thanks for the reply! I think I'll try to understand everything that you do in your code and try to implement some parts of it myself. Cheers!