Robert Mion

Posted on

## Part 1

1. Circular lists from the beginning!
2. Writing my working algorithm

### Circular lists from the beginning!

• I knew it was a recurring theme throughout the year
• But I didn't know it started with Day 1

### Writing my working algorithm

An outline of my algorithm

``````Split the input into an array of numbers
For each number
Accumulate a sum, starting a 0
If the next number (wrapping if necessary) is the same number
Increment the sum by the number at the current index
Otherwise, increment the sum by 0...leaving it unchanged
``````

A `reduce()` that leverages all of the possible parameters:

``````return input
.split('')
.map(Number)
.reduce((acc, curr, index, RA) =>
acc += RA[index] == RA[(index + 1) % RA.length]
? curr : 0
, 0)
``````

## Part 2

Instead of checking the next index, I'll check the index half a list away.

An outline of my algorithm

``````Split the input into an array of numbers
For each number
Accumulate a sum, starting a 0
If the number half a list length away (wrapping if necessary) is the same number
Increment the sum by the number at the current index
Otherwise, increment the sum by 0...leaving it unchanged
``````

A small tweak to the number being added to `index`, and Voila!

``````return input
.split('')
.map(Number)
.reduce((acc, curr, index, RA) =>
acc += RA[index] == RA[(index + (RA.length / 2)) % RA.length]
? curr : 0
, 0)
``````

## I did it!!

• I solved both parts!
• Using one long statement comprised of chained array methods!
• Where both parts only differ by a single operand!

## Year in review

Since I worked in reverse, today was the first time I saw this animation:

This static map should which puzzles I made simulators for:

• `46` stars! A new personal best!
• 21 two-star days! A new personal best!
• 4 one-star days! A new personal best!
• 0 no-star days! A new personal best!
• 8 simulators built! A tie with 2018 for lowest amount.
• Tons of GIFs created...many which helped me solve the puzzle!

It's been a blast, 2017!