Skip to main content

A template generator for Advent of Code solutions in Google Colab

Project description

Advent of Code Colab Template Generator

A simple template generator for Advent of Code solutions in Google Colab. This package provides an easy way to set up your Advent of Code environment in Colab notebooks with just a few commands.

Features

  • One-command template generation for AOC solutions
  • Automatic AOC session management
  • Easy data fetching for any day/year
  • Colab-specific optimizations

Installation

pip install aoc-colab-template

Quick Start

from aoc_colab_template import create_template
create_template()  # Creates template with all necessary imports and setup

Usage Guide

Setting Up Your Environment

The template generator creates a cell with all necessary imports and setup:

# This code is automatically generated by create_template()
from google.colab import userdata
import os
from aocd import get_data

# Sets up your AOC session automatically
AOC_SESSION = userdata.get('AOC_SESSION')
os.environ['AOC_SESSION'] = AOC_SESSION

Getting Puzzle Input

Basic Usage

# Get data for current day (defaults to day=1, year=2023)
data = get_aocd_data()

# Get data for specific day
day5_data = get_aocd_data(day=5)

# Get data from previous year
old_data = get_aocd_data(day=1, year=2022)

Working with Input Data

# Print first few lines
print(data.split('\n')[:5])

# Common data processing patterns
lines = data.splitlines()  # Split into lines
numbers = [int(x) for x in lines]  # Convert to integers
grid = [list(line) for line in lines]  # Create 2D grid

Best Practices

  1. Session Management

    • Store your AOC session token in Colab's userdata
    • The template handles the environment setup automatically
  2. Data Fetching

    • Use get_aocd_data() instead of copy-pasting inputs
    • Specify day and year explicitly for clarity
    • Cache data when working on solutions
  3. Template Usage

    • Run create_template() at the start of each new solution notebook
    • The template includes commonly needed imports
    • Form interface makes it easy to control package installation

Error Handling

Common Issues

  1. "AOC_SESSION not found":

    • Make sure you've stored your session token in Colab's userdata
    • Check that the template setup ran successfully
  2. "Not running in Colab":

    • This package only works in Google Colab environment
    • Check you're not running in a regular Jupyter notebook

Troubleshooting

If you encounter issues:

  1. Verify you're in a Colab environment
  2. Check your AOC session token is valid
  3. Ensure you have internet connectivity
  4. Try rerunning the template generation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - feel free to use this in your AOC solutions!

About Advent of Code

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

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

aoc_colab_template-0.1.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aoc_colab_template-0.1.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file aoc_colab_template-0.1.4.tar.gz.

File metadata

  • Download URL: aoc_colab_template-0.1.4.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.1

File hashes

Hashes for aoc_colab_template-0.1.4.tar.gz
Algorithm Hash digest
SHA256 d63f51cac3a82ce124fc54a2682a6a9c089ca7a3f16c4550f495d6f6c308185e
MD5 5cf4d9c8b352ebb6299bcb46c42b102b
BLAKE2b-256 e408a61306532c05e0232f5c37509b1577fc5b262e1aa52f776e27395a990eac

See more details on using hashes here.

File details

Details for the file aoc_colab_template-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for aoc_colab_template-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 251adb66807bf46d1b35714077fd91ad8310b14ccc1bbeb31786d17fc5912351
MD5 cca3e52fe1b7f7f8baa429388e6d39e5
BLAKE2b-256 8bcf8d9c73e86e74c69b1de9a19eae7347e765ed8ac6c090a7e53d2e74e43870

See more details on using hashes here.

Supported by

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