Skip to content

Instantly share code, notes, and snippets.

@dukeDanjou
Created September 6, 2014 17:25
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 dukeDanjou/73600a15e4977ef48c8d to your computer and use it in GitHub Desktop.
Save dukeDanjou/73600a15e4977ef48c8d to your computer and use it in GitHub Desktop.
CodinGame Easy 8 - Chuck Norris
// Read inputs from Standard Input (use readline()).
// Write outputs to Standard Output (use print()).
function textToBin(text) {
var length = text.length;
var output = "";
for (var i = 0;i < length; i++) {
var bin = text.charCodeAt(i).toString(2);
if( bin.length < 7 )
{
bin = "0" + bin;
}
output +=bin;
}
return output;
}
var encode = {
"0" : "00",
"1" : "0"
}
var binaryText = textToBin(readline());
var currentSign = binaryText[0];
var output = encode[currentSign]+" "+"0"
for(var i = 1 ; i < binaryText.length ; i++)
{
var nextBit = binaryText[i];
output += ( nextBit != currentSign ) ? " "+encode[nextBit]+" "+"0" : "0";
currentSign = nextBit;
}
print ( output );
@maliethy
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment