Created
December 5, 2018 19:34
-
-
Save willisplummer/a2a0e25499a18de55b3ff7937954e941 to your computer and use it in GitHub Desktop.
Advent of Code, Day 1 Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const input = [-14, -9, -14, -12, 13, 2, 7] // etc | |
let frequencies = [0]; | |
let winner = null; | |
while (!winner) { | |
const inputValue = input[(frequencies.length - 1) % input.length]; | |
const previousFrequency = frequencies[frequencies.length - 1]; | |
const newFrequency = previousFrequency + inputValue; | |
if (frequencies.includes(newFrequency)) { | |
winner = newFrequency; | |
} | |
frequencies.push(newFrequency); | |
} | |
console.log(winner); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment