Last active
December 5, 2018 05:42
-
-
Save lethern/af4a577402d5d917ce50fff2c39b483c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var diff = 'a'.codePointAt(0) - 'A'.codePointAt(0); | |
var N = 'z'.codePointAt(0) - 'a'.codePointAt(0); | |
fs.readFile('05_input', 'utf8', function (err, _contents) | |
{ | |
max = 1111111; | |
for (aa = 0; aa < N; ++aa) { | |
l = String.fromCodePoint(aa + 'a'.codePointAt(0)); | |
l2 = String.fromCodePoint(aa + 'A'.codePointAt(0)); | |
contents = _contents.replace(new RegExp(l, 'g'), ''); | |
contents = contents.replace(new RegExp(l2, 'g'), '').split``; | |
console.log(contents.length + ' ' + _contents.length); | |
i = 1; | |
while (i < contents.length) { | |
if (Math.abs(contents[i - 1].codePointAt(0) - contents[i].codePointAt(0)) == diff) { | |
contents.splice(i - 1, 2); | |
--i; | |
if (i < 1) i = 1; | |
} else { | |
++i; | |
} | |
} | |
if (contents.length < max) | |
max = contents.length; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment