Skip to content

Instantly share code, notes, and snippets.

@ldco2016
Created November 12, 2017 19:15
Show Gist options
  • Save ldco2016/13fce0c5fc31b98819bb32e96d7c44c3 to your computer and use it in GitHub Desktop.
Save ldco2016/13fce0c5fc31b98819bb32e96d7c44c3 to your computer and use it in GitHub Desktop.
function main() {
var S = readLine();
const expectedSignal = 'SOS';
let errorCount = 0;
for (i = 0, len = S.length; i <len; i += 3) {
const currentSignal = S.slice(i, i + 3);
if (currentSignal === expectedSignal) continue;
if (currentSignal[0] !== expectedSignal[0]) errorCount += 1;
if (currentSignal[1] !== expectedSignal[1]) errorCount += 1;
if (currentSignal[2] !== expectedSignal[2]) errorCount += 1;
}
console.log(errorCount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment