This repository contains my solutions for Advent of Code 2024 implemented in TypeScript.
advent-of-code-2024/
├── src/
│ ├── utils/ # Shared utility functions
│ └── dayXX/ # Daily solutions
│ ├── index.ts # Main entry point for each day
│ └── input.txt # Input file for the puzzle
├── scripts/ # Helper scripts
└── package.json
- Clone the repository
- Install dependencies:
npm installTo scaffold a new day's solution:
npm run new [day]This will create:
src/dayXX/index.ts- Solution template with part1 and part2 functionssrc/dayXX/input.txt- Empty input file for the puzzle
If no day is specified, it will use the current date.
To run a specific day's solution:
npm start [day]Each day's solution follows this template:
import { readInput } from '@utils/input';
function solve(input: string[]): any {
return 0; // Your solution logic here
}
if (require.main === module) {
const result = solve(readInput(__dirname));
console.log(result);
}The project includes several utility functions to help with input parsing:
readInput(day: number): string- Reads the entire input file as a stringreadLines(day: number): string[]- Reads the input file and splits it into linesreadNumbers(day: number): number[]- Reads the input file and converts each line to a number