Created
July 7, 2016 00:28
-
-
Save zettca/6c1e33168991eb84a4a505a570897ed3 to your computer and use it in GitHub Desktop.
AdventOfCode Day10 challenge
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
"use strict"; | |
String.prototype.solve = function(){ | |
let str = this; | |
let digit = str[0]; | |
let count = 1; | |
let res = ""; | |
for (var i=1; i<str.length; i++){ | |
if (str[i] == digit){ | |
count++; | |
} else{ | |
res += count + digit; | |
digit = str[i]; | |
count = 1; | |
} | |
} | |
return res + count + digit; | |
}; | |
const ITERS = 50; | |
let timeStart = Date.now(); | |
var puzz = "1113122113"; | |
for (let i=0; i<ITERS; i++) puzz = puzz.solve(); | |
console.log("ELLAPSED: " + (Date.now()-timeStart) + "ms"); | |
console.log("SOLUTION: " + puzz.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment