adventofcode-2016/day20/part1.js
2016-12-20 10:49:06 +00:00

6 lines
357 B
JavaScript

var min = 0;
var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
var ranges = input.split("\n").filter((a)=>(a)).map((line)=>(line.split("-").map((num)=>(parseInt(num))))).sort((a, b)=>(a[0] - b[0]));
var min = ranges.reduce((min, range)=>((min >= range[0]) && (min <= range[1]) ? (range[1] + 1) : min), 0);
console.log(min);