import * as std from "std"; var data = std.loadFile("11.txt").trim().split('n'); for (var i = 0; i < data.length; i++) { data[i] = data[i].split(' '); data[i] = data[i].map(x=>Number(x)); } var high = 0; data.forEach(function(line) { for (var i = 0; i < line.length-4; i++) { var n = line.slice(i,i+4).reduce((a,c) => a *= c); high = n > high ? n : high; } }); for (var i = 0; i < data[0].length-4; i++) { for (var j = 0; j < data[0].length; j++) { console.log(`${i},${j}`); var n = data[i][j]*data[i+1][j]*data[i+2][j]*data[i+3][j]; console.log(`${i},${j}`); high = n > high ? n : high; } } console.log(high);