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Zbl\nnfmsqppnLfTnfmMmzppwgllSrbSHHtllqbtSwZ\nTRzTnfRWnfdzWssfnRfRpncQPBhdDjjDCPcMQcCBGPPj\nNSjWCHjNHjpPWPpSFWdtqBMBBFVBvqvJGJwqBt\ngQllgDrnhQQDGRshRsZfVtVMRqwMtccVJcBtvRqw\nDQrzrDzhQgrsZLrZjWSSHNTWCjjNGTLH\nCgdcCFcbTbBzPgmNRmpptP\nrsZtsvVvHZZzPmqVNPzNmV\nHZjrwrjnjtHSHwDGdFhCdhWWJnWchCFJ\nRMTqQMRJqPtBtGBPtWjN\nssHfSfShCwwbhsbHhhsmSfhSGNpCpNCjBBBLptcGtpzBBBWW\nHnwrSFwffHsFwrSSjfHglJJlTgZdFdgZRZTDDM\npDLDWlDSlJDmzSJnDScRPLGGvqFqLPccGLgv\nCZHfwNMVNjsHNNqPgcbcBbRQGQ\ndCffZCjVCdCHHTmnlSgTlTSrlStp\nbFtlLCvLlVjpCGPJndrrMMCDDCnrMg\nhRsTwcZcBjZRJrfMDnsHrJnH\nmNZqcTSSBTScNzVQFtGtjpFtjmGG\nbjHdLrHjRWpDCtLzhzps\nlZcGfTvQcQfvlqqcNCcBvVwtGzmzthmwmpthMDmswgMt\nNcqflNQTBTTvvQSvqSVvQJbHPHbHCRJdndJPSHjWHb\nCVmRncrRVrhcmsBgfmtfdJsJmt\nbZHvZZDJwpWtdZgtGNGd\nvSbwHDMFMJqPQqQvvSPQqpSwjRcTVTLjLRhVCLFLjLFnFzCC\nmtffsmBwfwBDBmmsLsHqtpftGrMVMPSMPsVvhNvFrGPMvjNV\nTQTQCRWjJcdcQQSPrhhPSvVGPF\ncTRJCnldWJZlTgbWgbdbpqfqmppjmtljpqzmjpLw\nNNPmrmPWmrSSNNPmnglghmCvLC
|
||
|
|
||
|
const getPriority = (char) => {
|
||
|
const code = char.charCodeAt(0);
|
||
|
if(code < 92) {
|
||
|
return code - 38;
|
||
|
}
|
||
|
return code - 96;
|
||
|
}
|
||
|
|
||
|
const main = async () => {
|
||
|
const sacks = input.split("\n").map(r => r.split(''));
|
||
|
let sum = 0;
|
||
|
console.log(sacks);
|
||
|
for(let i = 0; i < sacks.length; i = i + 3) {
|
||
|
const group = sacks.slice(i, i + 3);
|
||
|
console.log("Group: ", group);
|
||
|
const badge = group[0].find(item => group[1].includes(item) && group[2].includes(item));
|
||
|
console.log("found badge: ", badge);
|
||
|
sum += getPriority(badge);
|
||
|
};
|
||
|
|
||
|
return sum;
|
||
|
|
||
|
};
|
||
|
|
||
|
|
||
|
main().then(r => console.log("Result: ", r));
|