diff --git a/2017/src/day01.spec.ts b/2017/src/day01.spec.ts index 93dca76..b5578ff 100644 --- a/2017/src/day01.spec.ts +++ b/2017/src/day01.spec.ts @@ -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) + }); + });