Skip to content

Commit

Permalink
2017: Add day 1 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jp7677 committed Dec 15, 2024
1 parent ca622ea commit b5ef05d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 2017/src/day01.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@ describe('day 01', () => {
expect(sum).toBe(1029)
});

test('part 2', async () => {
const input = await readInput('day01-input.txt')
const captcha = input[0].split('').map(c => parseInt(c))

const forward = captcha.length / 2
const array = [...captcha, ...captcha]

const sum = captcha
.reduce((acc, it, idx) => {
if (it == array[idx+forward])
return acc + it
else
return acc
}, 0)

expect(sum).toBe(1220)
});

});

0 comments on commit b5ef05d

Please sign in to comment.