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)));