Created
September 6, 2014 17:25
-
-
Save dukeDanjou/73600a15e4977ef48c8d to your computer and use it in GitHub Desktop.
CodinGame Easy 8 - Chuck Norris
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!