Advent of Code Generator
A Ruby gem that generates daily puzzle templates for Advent of Code with automatically scraped puzzle descriptions and input data.
Installation
gem install advent_of_code_generator
Prerequisites
- RSpec: This gem uses RSpec for testing. If you haven't installed it yet, run:
gem install rspec
- Or optionally, set it up as you would for a normal Ruby project by adding
rspecto yourGemfileand runningbundle install.
Setting up your session key
- Log in to Advent of Code
- In your browser's developer tools, find the
sessioncookie value- Chrome: DevTools (F12) > Application > Cookies > adventofcode.com
- Firefox: DevTools (F12) > Storage > Cookies
- Store the session key in your environment:
# Add to your ~/.bashrc, ~/.zshrc, or equivalent
export AOC_SESSION='your_session_key_here'
Usage
# With default arguments
aoc generate
# With custom arguments
aoc generate -y=2023 -d=1 -u=cheddachedda -s=$SESSION_KEY
Options
-y, [--year=N] # Defaults to the current year.
-d, [--day=N] # Defaults to the current day.
-u, [--username=USERNAME] # Files will be generated in a directory with this name. Useful for multi-user repos.
# Default: advent_of_code
-s, [--session=SESSION] # Your adventofcode.com session key. Necessary for scraping data files and specs for part two.
# Default: reads AOC_SESSION environment variable if it exists.
Generated file structure
adventofcode/
│
└── year_2024/
|
└── day_01/
├── day_01.rb
├── day_01_spec.rb
├── data.txt
└── PUZZLE_DESCRIPTION.md
Generated File Contents
The generator creates the following files with basic templates:
day_XX.rb
class DayXX
def part_one(input)
# Your solution for Part One
end
def part_two(input)
# Your solution for Part Two
end
end
day_XX_spec.rb
RSpec.describe Cheddachedda::YearXXXX::DayXX do
it "solves Part One" do
input = " 1abc2\n pqr3stu8vwx\n a1b2c3d4e5f\n treb7uchet\n INPUT\n\n expect(described_class.part_one(input)).to eq(142)\n end\n\n # it \"solves Part Two\" do\n # input = <<~INPUT\n # two1nine\n # eightwothree\n # abcone2threexyz\n # xtwone3four\n # 4nineeightseven2\n # zoneight234\n # 7pqrstsixteen\n # INPUT\n\n # expect(described_class.part_two(input)).to eq(281)\n # end\nend\n"
Acknowledgments
- Thanks to Eric Wastl for creating Advent of Code