2018 d5 js
This commit is contained in:
parent
3c9349a63c
commit
12f9f51921
1
2018/5/input.txt
Normal file
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
8
2018/5/part1.js
Normal 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
19
2018/5/part2.js
Normal 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);
|
|
@ -16,6 +16,7 @@ It's a fun challenge from [here](https://adventofcode.com).
|
|||
* [2](https://adventofcode.com/2018/day/2) py * *
|
||||
* [3](https://adventofcode.com/2018/day/3) js * *
|
||||
* [4](https://adventofcode.com/2018/day/4) js * *
|
||||
* [5](https://adventofcode.com/2018/day/5) js * *
|
||||
|
||||
# Languages Used
|
||||
* Python
|
||||
|
|
Loading…
Reference in a new issue