adventofcode-2018/05/part2.js

22 lines
563 B
JavaScript
Raw Permalink Normal View History

2018-12-06 00:10:48 +00:00
var input = require("fs").readFileSync("input.txt").toString().replace("\n", "");
replace = str=>(str.split("").filter(a=>(a!="\n")).reduce((a,b)=>{
var c = a.pop();
if(c){
if(!((b!=c) && (b.toLowerCase()==c.toLowerCase()))){
a.push(c);
a.push(b);
}
}
else{
a.push(b);
}
return a;
}, []).join(""));
var strs = [];
for(var i = 0; i < 26; i++){
strs.push(input.split("").filter((a)=>(a.toLowerCase().charCodeAt(0) != (97 + i))).join(""));
}
var lengths = strs.map(a=>(replace(a))).map(a=>(a.length));
console.log(Math.min.apply(null, lengths));