adventofcode-2016/day06/part2.js

7 lines
487 B
JavaScript
Raw Normal View History

2016-12-06 15:43:19 +00:00
var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
var groups = input.split("\n").reduce((a, b)=>{b.split("").forEach((x, i)=>{if(!a[i]){a[i] = [];} a[i].push(x);}); return a;}, []);
var freqs = groups.map((g)=>(g.reduce((a, b)=>{if(!a[b]){a[b] = 0;}; a[b]++; return a;}, {})));
var largest = freqs.map((f)=>(Object.keys(f).map((l)=>[l, f[l]]))).map((f)=>(f.sort((a, b)=>(a[1] - b[1])))).map((a)=>(a[0][0]));
var key = largest.join("");
console.log(key);