3

Advent of code Day 1 Part 2

 2 years ago
source link: https://gist.github.com/harishvadali/b2f4abd34e79d72be31406d491173ed0
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Advent of code Day 1 Part 2 · GitHub

Instantly share code, notes, and snippets.

Advent of code Day 1 Part 2

let numbers = input.split(' '); let startingNumber = +numbers[0]; let prevTotal = 0; let runningTotal = 0; let increased = 0;

for (let i=1; i<numbers.length; i++) { if (i > 2) { prevTotal = runningTotal; runningTotal += +numbers[i]; runningTotal -= +numbers[i-3]; if (runningTotal > prevTotal) increased++; } else { runningTotal += +numbers[i]; } }

console.log(increased);


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK