X = the resulting frequency - starting from 0 - after all of the changes in frequency have been applied
X = the first frequency my device reaches twice
+1 -2 +3 +1
- A series of frequency changes
+is an increase in frequency
-is a decrease in frequency
My proposed algorithm:
Generate an ordered list of numbers from the input For each number Accumulate a sum - starting at 0 Return the sum
reduce() to make this a very simple task:
input.split('\n').map(Number).reduce((a,c) => a + c)
It worked as anticipated, generating a correct answer!
Set a list of frequency history, starting with one element: 0 Set frequency as 0 Set index as 0 Do as long as the last item in the list is not found elsewhere in the list If index is equal to the length of the list Reset index to 0 Increment frequency by the number change at the current index in the list of frequency changes Insert the new frequency at the end of history Increment index by 1 Return the last item in the history list
It took over 30 seconds to run, but it generated the correct answer!
- I solved both parts!
- I solved Part 1 using one concise line of code!
- My algorithm for Part 2 takes a long time to run...longer than I expected
- I'm not sure how I'd write a more performant algorithm to generate the correct answer in milliseconds instead of seconds
- I got 35 gold stars!
- I beat my low score by 1!
- I made 8 simulators! That's my lowest amount in a year thus far, but each one was a delight to make.
- This felt like the toughest year
- I still am frustrated that I didn't solve Day 24. It would have been fun to build that simulator.
- 100 puzzles attempted thus far!
- Out of 200 stars possible, I've earned 143!
- That's nearly 75% of the stars!
- Not bad for someone like me who is not a trained Software Engineer, Computer Scientist or Programmer
Onward, to 2017!