-
-
Save TristanWiley/fdc1d13424dd24b845eeeae43fc1c897 to your computer and use it in GitHub Desktop.
This file contains 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
//Run this directly in the browser console for the input | |
var text = document.body.textContent.split('\n'); | |
var checksums = []; | |
var answer = 0; | |
for (var i = 0; i < text.length; i++) { | |
var curText = text[i]; | |
var cs = curText.match(/[^[\]]+(?=])/g); | |
if (cs) { | |
checksums.push(cs); | |
} | |
curText = curText.substring(0, curText.indexOf('\[')); | |
var testing = ""; | |
//worst way to do this but fuck it I'm tired | |
getFrequency(curText).reverse().forEach(function(entry) { | |
testing+=entry[0]; | |
// for (var i = 0; i < getFrequency(curText).length; i++) { | |
// if(entry==getFrequency(curText)[i][0]){ | |
// console.log(getFrequency(curText)[i][0]); | |
// } | |
// } | |
}); | |
// console.log(testing.substring(0,5)); | |
var finalString = testing.substring(0, 5).split('').sort().join(''); | |
if (cs==finalString) { | |
console.log(finalString); | |
console.log(cs[0]); | |
answer+=Number(curText.split("-")[curText.split("-").length-1]); | |
} | |
} | |
console.log(answer); | |
function getFrequency(string) { | |
var freq = {}; | |
for (var i = 0; i < string.length; i++) { | |
var character = string.charAt(i); | |
if (character != "-") { | |
if (freq[character]) { | |
freq[character]++; | |
} else { | |
freq[character] = 1; | |
} | |
} | |
} | |
var sortable = []; | |
for (var number in freq) | |
sortable.push([number, freq[number]]) | |
sortable.sort(function(a, b) { | |
return a[1] - b[1] | |
}) | |
return sortable; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment