Skip to content

Instantly share code, notes, and snippets.

@adk96r
Last active March 28, 2026 19:35
Show Gist options
  • Select an option

  • Save adk96r/915ad848c724134f873395234dda0b1a to your computer and use it in GitHub Desktop.

Select an option

Save adk96r/915ad848c724134f873395234dda0b1a to your computer and use it in GitHub Desktop.
Solution for AoC#2
const allReports = `` // For simplicity, I chose to keep the input here instead of accepting as CLI input
const splitReports = allReports.split('\n')
.filter(report => report.length)
.map(report => report.split(' ').map(val => parseInt(val)))
function isReportSafe(report) {
const isIncreasing = report[0] < report[1];
return report.every((val, i) => {
if (i === 0) return true; // skip initial position
const diff = val - report[i - 1];
return isIncreasing ? diff >= 1 && diff <= 3 : diff >= -3 && diff <= -1;
});
}
const safeReports = splitReports.filter(isReportSafe)
console.log(safeReports.length)
// Solution is 411
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment