2018 d5 js

This commit is contained in:
Tristan 2018-12-05 07:39:48 +00:00
parent 3c9349a63c
commit 12f9f51921
4 changed files with 29 additions and 0 deletions

1
2018/5/input.txt Normal file

File diff suppressed because one or more lines are too long

8
2018/5/part1.js Normal file
View file

@ -0,0 +1,8 @@
const fs = require('fs');
let input = fs.readFileSync('input.txt', 'utf-8');
let exp = /(qQ|wW|eE|rR|tT|yY|uU|iI|oO|pP|aA|sS|dD|fF|gG|hH|jJ|kK|lL|zZ|xX|cC|vV|bB|nN|mM|Qq|Ww|Ee|Rr|Tt|Yy|Uu|Ii|Oo|Pp|Aa|Ss|Dd|Ff|Gg|Hh|Jj|Kk|Ll|Zz|Xx|Cc|Vv|Bb|Nn|Mm)/g;
while (input.match(exp)) {
input = input.replace(exp, '')
}
console.log(input)
console.log(input.length)

19
2018/5/part2.js Normal file
View file

@ -0,0 +1,19 @@
const fs = require('fs');
let input = fs.readFileSync('input.txt', 'utf-8');
let exp = /(qQ|wW|eE|rR|tT|yY|uU|iI|oO|pP|aA|sS|dD|fF|gG|hH|jJ|kK|lL|zZ|xX|cC|vV|bB|nN|mM|Qq|Ww|Ee|Rr|Tt|Yy|Uu|Ii|Oo|Pp|Aa|Ss|Dd|Ff|Gg|Hh|Jj|Kk|Ll|Zz|Xx|Cc|Vv|Bb|Nn|Mm)/g;
function react(input) {
while (input.match(exp)) {
input = input.replace(exp, '')
}
return input
}
let best = Infinity;
for (let char of 'qwertyuiopasdfghjklzxcvbnm') {
let inp = input.replace(new RegExp(char, 'ig'), '');
let out = react(inp)
best = Math.min(best, out.length)
}
console.log(best);

View file

@ -16,6 +16,7 @@ It's a fun challenge from [here](https://adventofcode.com).
* [2](https://adventofcode.com/2018/day/2) py * * * [2](https://adventofcode.com/2018/day/2) py * *
* [3](https://adventofcode.com/2018/day/3) js * * * [3](https://adventofcode.com/2018/day/3) js * *
* [4](https://adventofcode.com/2018/day/4) js * * * [4](https://adventofcode.com/2018/day/4) js * *
* [5](https://adventofcode.com/2018/day/5) js * *
# Languages Used # Languages Used
* Python * Python