adventofcode-2017/day02/part1.js

6 lines
411 B
JavaScript
Raw Normal View History

2017-12-02 12:59:01 +00:00
var input = require("fs").readFileSync("input.txt").toString();
var rows = input.split("\n").filter((a)=>(a)).map((a)=>(a.split("\t").map((b)=>(parseInt(b)))));
var columns = rows.reduce((a, row, y)=>{row.forEach((b, x)=>{if(!a[x]){a[x]=[]}; a[x][y] = b;}); return a;}, []);
var differences = rows.map((a)=>(Math.max.apply(null, a) - Math.min.apply(null, a)));
console.log(differences.reduce((a, b)=>(a + b)));