My solutions to the Advent of Code 2024 challenges, implemented in TypeScript with a focus on clean, maintainable code.
Features • Setup • Usage • Development
- 🚀 Automatic Input Fetching - Downloads puzzle inputs with session token
- ✅ Answer Validation - Verifies solutions against AoC API
- 📝 Type Safety - Full TypeScript with strict checking
- 🔄 Hot Reloading - Instant feedback during development
- 🧪 Consistent Structure - Standardized solution template
- 💾 Input Caching - Offline development support
- ⚡ Performance Tracking - Solution execution timing
- 🛠️ Developer Tools - ESLint, Prettier, and more
- Node.js 20.x or later
- npm 9.x or later
- Advent of Code session token
-
Clone and Install
git clone [your-repo-url] cd advent-of-code_2024 npm install
-
Configure Environment
# Create .env file echo "AOC_SESSION=your_session_token_here" > .env
To get your session token:
- Log into Advent of Code
- Open DevTools (F12) → Application → Storage → Cookies
- Copy the 'session' cookie value
advent-of-code_2024/
├── solutions/ # Daily puzzle solutions
│ ├── day-{N}/ # Individual day solutions (1-25)
│ │ └── index.ts # Solution implementation
│ └── template/ # Solution template files
├── utils/ # Shared utilities
│ ├── cache.ts # Input caching functionality
│ ├── checkAnswer.ts # Solution validation
│ ├── dates.ts # Date handling utilities
│ ├── errors.ts # Custom error types
│ ├── getInput.ts # Puzzle input fetcher
│ ├── index.ts # Utility exports
│ ├── performance.ts # Timing utilities
│ └── runner.ts # Solution runner
├── scripts/ # Project automation
│ └── create-day.ts # Solution scaffolding
├── templates/ # Project templates
├── dist/ # Compiled output
├── .cache/ # Cached puzzle inputs
└── node_modules/ # Dependencies
- solutions/: Contains daily puzzle solutions, each in its own directory with a standardized structure
- utils/: Shared utilities for input handling, performance tracking, and solution validation
- scripts/: Automation tools for project management and solution creation
- templates/: Template files for generating new solutions
- dist/: Compiled TypeScript output
- .cache/: Local cache for puzzle inputs (git-ignored)
Each day's solution follows a consistent pattern:
solutions/day-N/
└── index.ts # Main solution file containing:
├── formatInput() # Input parser
├── solvePart1() # Part 1 solution
└── solvePart2() # Part 2 solution
The solution template includes:
- Strong TypeScript types
- Error handling with custom AoCError
- Performance tracking via the timed() wrapper
- Standardized input parsing
- Consistent error reporting
This structure ensures consistency across solutions while maintaining clean separation of concerns and reusable utilities.
# Run specific day
DAY=N npm run start:day # N = 1-25
# Run current day
npm run day
# Run latest solution (that you've created; good when you're a day or more behind)
npm run start:latest
# Development mode with hot reload
DAY=N npm run dev
# Format code
npm run format
# Lint code
npm run lint
npm run lint:fix
# Build project
npm run build
# Run with test input
DAY=N npm run start:day:test
# Run current day with test input
npm run day:test
# Run latest solution with test input (that you've created; good when you're a day or more behind)
npm run start:latest:test
# Development mode with test input
DAY=N npm run dev:test
The project includes scripts to create the necessary file structure for solutions:
# Create a single day's files
npm run new N # Replace N with day number (1-25)
# Create files for all 25 days at once
npm run new:all
- Language: TypeScript 5.7
- Runtime: Node.js 20.x
- Module System: ESM
- Development:
- ESLint
- Prettier
- tsx (for hot reloading)
Input files are cached in /dist/.cache/
:
- Minimizes API requests
- Enables offline work
- Improves performance
- Git-ignored by default
Taylor Sabbag
⭐ Star this repository if you find it helpful!
Made with ❤️ for Advent of Code