63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { Game, calculatePossibleGames, calculateMinimumCubePowers } from "./day_two.alternative";
|
|
|
|
const partOneInput = `Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
|
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
|
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green`
|
|
|
|
describe('Day Two', () => {
|
|
it('should parse a game', () => {
|
|
const games = partOneInput.split('\n').map(Game.parse);
|
|
expect(games).toEqual([
|
|
new Game(1, [
|
|
{ blue: 3, green: 0, red: 4 },
|
|
{ blue: 6, red: 1, green: 2 },
|
|
{ blue: 0, red: 0, green: 2 }
|
|
]
|
|
),
|
|
new Game(2, [
|
|
{ blue: 1, green: 2, red: 0 },
|
|
{ blue: 4, red: 1, green: 3 },
|
|
{ blue: 1, red: 0, green: 1 }
|
|
]
|
|
),
|
|
new Game(
|
|
3,
|
|
[
|
|
{ blue: 6, green: 8, red: 20 },
|
|
{ blue: 5, red: 4, green: 13 },
|
|
{ blue: 0, red: 1, green: 5 }
|
|
]
|
|
),
|
|
new Game(
|
|
4,
|
|
[
|
|
{ blue: 6, green: 1, red: 3 },
|
|
{ blue: 0, red: 6, green: 3 },
|
|
{ blue: 15, red: 14, green: 3 }
|
|
]
|
|
),
|
|
new Game(
|
|
5,
|
|
[
|
|
{ blue: 1, green: 3, red: 6 },
|
|
{ blue: 2, red: 1, green: 2 },
|
|
]
|
|
)
|
|
]);
|
|
});
|
|
|
|
it('should calculate which games should only have been possible with the number of cubes', () => {
|
|
const games = partOneInput.split('\n').map(Game.parse);
|
|
expect(calculatePossibleGames(games, {
|
|
blue: 14,
|
|
red: 12,
|
|
green: 13
|
|
})).toEqual(8);
|
|
});
|
|
it('should find the minimum cubes in a set and sum the powers of the cubes', () => {
|
|
const games = partOneInput.split('\n').map(Game.parse);
|
|
expect(calculateMinimumCubePowers(games)).toEqual(2286);
|
|
});
|
|
}); |