Skip to content

Instantly share code, notes, and snippets.

@leyanlo
Created December 8, 2021 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leyanlo/28434c2bc80134489023dd56b7884b10 to your computer and use it in GitHub Desktop.
Save leyanlo/28434c2bc80134489023dd56b7884b10 to your computer and use it in GitHub Desktop.
const exampleSignals =
'acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab';
const charCount = {};
for (const char of exampleSignals
.split('')
.filter((char) => /[a-g]/.test(char))) {
charCount[char] = (charCount[char] ?? 0) + 1;
}
function charCountSum(signal) {
return signal.split('').reduce((acc, char) => acc + charCount[char], 0);
}
const charCountSumToDigit = {
[charCountSum('acedgfb')]: 8,
[charCountSum('cdfbe')]: 5,
[charCountSum('gcdfa')]: 2,
[charCountSum('fbcad')]: 3,
[charCountSum('dab')]: 7,
[charCountSum('cefabd')]: 9,
[charCountSum('cdfgeb')]: 6,
[charCountSum('eafb')]: 4,
[charCountSum('cagedb')]: 0,
[charCountSum('ab')]: 1,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment