Cover image for Introducing The Advent of Code Cookiecutter

Introducing The Advent of Code Cookiecutter

lachlaneagling profile image Lachlan Eagling Originally published at lachlaneagling.com on ・2 min read

Well, it's that time of year again with the fresh 2019 Advent of Code challenges landing today. In years past I have constantly found myself repeating myself with writing out function stubs, unit tests, creating files to hold challenge input and results etc.

This year I have done all the work upfront, introducing the Advent of Code Cookie-cutter a Python project to bootstrap your Advent of Code efforts. Out of the box, it provides function stubs for implementing solutions to all the challenges, empty files to simply drop your challenge inputs and answers into, and then unit tests to provide peace of mind when refactoring and improving solutions to the challenges.

Below is an example of solving the part 1 of the first challenge from the 2018 Advent of Code challenges with the Advent of Code Cookie-cutter project.

from advent_of_code.utils import load_input, save_answers

INPUT = load_input(1)

def part1():
    return sum(int(x) for x in INPUT)

def part2():
    return "Challenge not solved"

if __name__ == " __main__":
    answer1 = part1()
    answer2 = part2()
    print(f"Day 1 - Part 1 Answer: {answer1}")
    print(f"Day 1 - Part 2 Answer: {answer2}")
    save_answers(answer1, 1, 1)
    save_answers(answer2, 1, 2)

Once the output answer has been verified as correct unit tests can be executed across all of the challenges to ensure that the answer remains correct when refactoring and improving solutions.

Advent of Code Cookiecutter - Unit Test Execution

For instructions on getting up and running with this, see the Github project. Suggested improvements are encouraged and welcome too 🙏.

Posted on Oct 6 '19 by:

lachlaneagling profile

Lachlan Eagling


I am a software developer working mostly with Python & Go. I love delving into technical problems and challenges & writing about my experiences exploring software engineering and technology.


markdown guide