Skip to content

Instantly share code, notes, and snippets.

@willisplummer
Created December 5, 2018 19:34
Show Gist options
  • Save willisplummer/a2a0e25499a18de55b3ff7937954e941 to your computer and use it in GitHub Desktop.
Save willisplummer/a2a0e25499a18de55b3ff7937954e941 to your computer and use it in GitHub Desktop.
Advent of Code, Day 1 Part 2
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