import * as std from 'std'; var data = std.loadFile('13.txt'); data = data.trim().split('\n\n'); for (var i = 0; i < data.length; i++) data[i] = data[i].split('\n'); function reflect(coords, mirr) { var ret = {}; ret.x = coords.x*-1; ret.y = coords.y*-1; return ret; } var height = 7; var width = 9; var sum = 0; data.forEach(function(d) { // d.forEach((p,i)=>console.log(`${(i+1).toString().padStart(2,'0')} ${p}`)); /* check verticals */ outer: for (var m = 0; m < d.length-1; m++) { for (var i = 0; i <= m ; i++) { for (var j = 0; j < d[i].length; j++) { var s = d[i][j]; var mj = j; var mi = 2*m-i+1; if (!d[mi]) continue; if (s !== d[mi][mj]) continue outer; } } sum += 100*(m+1); return; } /* horizontals */ outer: for (var m = 0; m < d[0].length-1; m++) { for (var i = 0; i < d.length; i++) { for (var j = 0; j <= m; j++) { var s = d[i][j]; var mi = i; var mj = 2*m-j+1; if (!d[mi][mj]) continue; if (s !== d[mi][mj]) continue outer; } } sum += m+1; return; } }); console.log(sum); sum = 0; data.forEach(function(d) { /* check verticals */ outer: for (var m = 0; m < d.length-1; m++) { var wrong = undefined; var rfl = 0; for (var i = 0; i <= m ; i++) { for (var j = 0; j < d[i].length; j++) { var s = d[i][j]; var mj = j; var mi = 2*m-i+1; if (!d[mi]) continue; if (s !== d[mi][mj]) { if (wrong) continue outer; wrong = [i,j]; rfl = m; } } } if (wrong) { var m = rfl; sum += 100*(m+1); return; } } /* horizontals */ outer: for (var m = 0; m < d[0].length-1; m++) { var wrong = undefined; var rfl = 0; for (var i = 0; i < d.length; i++) { for (var j = 0; j <= m; j++) { var s = d[i][j]; var mi = i; var mj = 2*m-j+1; if (!d[mi][mj]) continue; if (s !== d[mi][mj]) { if (wrong) continue outer; wrong = [i,j]; rfl = m; } } } if (wrong) { var m = rfl; sum += m+1; return; } } }); console.log(sum);