Last active
August 29, 2015 14:01
-
-
Save JonathanMatthey/d65a400ad9ea2c86b9ce to your computer and use it in GitHub Desktop.
codecon bloomberg 4
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
//Problem : The Verbal Literal | |
//Language : Javascript | |
//Compiled Using : V8 | |
//Version : Node 0.10.25 | |
//Input for your program will be provided from STDIN | |
//Print out all output from your program to STDOUT | |
//0rw3ll | |
//0rw3ll | |
var readline = require('readline'), | |
//0rw3ll | |
rl = readline.createInterface({ | |
//0rw3ll | |
input: process.stdin, | |
//0rw3ll | |
output: process.stdout, | |
//0rw3ll | |
terminal: false | |
//0rw3ll | |
}); | |
//0rw3ll | |
//0rw3ll | |
rl.on('line', function (command) | |
//0rw3ll | |
{ | |
//0rw3ll | |
command = command.split(/\W/).map(function (i) { return parseInt(i); }); | |
//0rw3ll | |
//0rw3ll | |
var line = String(command[0]), | |
//0rw3ll | |
iter = command[1]; | |
//0rw3ll | |
//0rw3ll | |
for (var i = 0; i < iter; i ++) { | |
//0rw3ll | |
var next1 = [], | |
//0rw3ll | |
c = line[0], | |
//0rw3ll | |
n = 0; | |
//0rw3ll | |
//0rw3ll | |
for (var j = 0; j < line.length; j++) { | |
//0rw3ll | |
if (line[j] === c) { | |
//0rw3ll | |
n++; | |
//0rw3ll | |
} else { | |
//0rw3ll | |
next1.push(n); | |
//0rw3ll | |
next1.push(c); | |
//0rw3ll | |
//0rw3ll | |
c = line[j]; | |
//0rw3ll | |
n = 1; | |
//0rw3ll | |
} | |
//0rw3ll | |
} | |
//0rw3ll | |
next1.push(n); | |
//0rw3ll | |
next1.push(c); | |
//0rw3ll | |
//0rw3ll | |
line = next1.join(''); | |
//0rw3ll | |
} | |
//0rw3ll | |
//0rw3ll | |
console.log(line.length); | |
//0rw3ll | |
process.exit(0); | |
//0rw3ll | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment