Skip to content

Commit 60db59d

Browse files
committed
refactor: make API independent of array
1 parent 3be60f2 commit 60db59d

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

day22/cardshuffle.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ export const parseActions = (actions: string): CardAction[] =>
4747

4848
export const cardShuffle = (actions: CardAction[]) => (deck: Deck): Deck =>
4949
actions.reduce((deck, action) => action(deck), deck)
50+
51+
export const deckOf = (length: number): number[] =>
52+
[...Array(length)].map((_, i) => i)
53+
54+
export const positionInDeck = (deck: Deck) => (card: number) =>
55+
deck.indexOf(card)

day22/day21.solution.spec.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

day22/day22.solution.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
cardShuffle,
3+
parseActions,
4+
deckOf,
5+
positionInDeck,
6+
} from './cardshuffle'
7+
import * as fs from 'fs'
8+
import * as path from 'path'
9+
10+
const actions = fs.readFileSync(
11+
path.resolve(process.cwd(), 'day22/input.txt'),
12+
'utf-8',
13+
)
14+
15+
describe('Day 22: Part 1', () => {
16+
it('should solve the puzzle', () => {
17+
const deck = deckOf(10007)
18+
const shuffled = cardShuffle(parseActions(actions))(deck)
19+
expect(positionInDeck(shuffled)(2019)).toEqual(3749)
20+
})
21+
})

0 commit comments

Comments
 (0)