Advent of Code Framework (aocf)
Framework for working with Advent of Code in typescript
Usage
Can be used to structure puzzles as classes
import {AoC} from 'aocf'
export class AoC2020Day1 extends AoC {
partA(input: string):number {
return 95;
}
partB(input: string): number {
return 105;
}
}
new AoC2020Day1.run()
Or used as a script format
import {AoC} from 'aocf'
const aoc = AoC.create(2020, 1)
const input = await aoc.input
Or as a combination
import {AoC} from 'aocf'
const aoc = AoC.create(2020, 1);
aoc.partA = (d) => {
let total = 0;
for (const line of d.split('\n')) total++;
return total;
};
aoc.run();
Export
All answers and input can be export into a JSON file for sharing
import '@blacha/advent-of-code-2020';
const data = await AoC.export(2020);
writeFileSync(`./aoc-${data.user}-${data.year}.json`, JSON.stringify(data, null, 2));
Format:
export interface AoCJsonData {
user: string;
year: number;
puzzles: {
input: string;
answers: { a: string | number, b: string | number}
}[]
}
Configuration
Session and data storage locations can be configured with a .aocrc
or environment variables
AOC_SESSION=YourAoCSession
AOC_USER=blacha
AOC_DATA_PATH=.
export AOC_SESSION=YourAoCSession