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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 getValue = (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(''));
|
||
|
const compartments = sacks.map(sack => [sack.slice(0, (sack.length + 1)/2), sack.slice((sack.length+1)/2)]);
|
||
|
const doubles = compartments.map(([comp1, comp2]) => comp1.find(c => comp2.includes(c)));
|
||
|
return doubles.map(getValue).reduce((sum, a) => sum + a, 0);
|
||
|
|
||
|
};
|
||
|
|
||
|
|
||
|
main().then(r => console.log("Result: ", r));
|