more days

This commit is contained in:
2018-12-06 00:10:48 +00:00
parent 1a085be4db
commit edd783b3e4
11 changed files with 2460 additions and 0 deletions

1
05/input.txt Normal file

File diff suppressed because one or more lines are too long

15
05/part1.js Normal file
View File

@ -0,0 +1,15 @@
var input = require("fs").readFileSync("input.txt").toString();
var replaced = input.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("");
console.log(replaced.length);

21
05/part2.js Normal file
View File

@ -0,0 +1,21 @@
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));