Skip to content

Instantly share code, notes, and snippets.

@zettca
Created July 7, 2016 00:28
Show Gist options
  • Save zettca/6c1e33168991eb84a4a505a570897ed3 to your computer and use it in GitHub Desktop.
Save zettca/6c1e33168991eb84a4a505a570897ed3 to your computer and use it in GitHub Desktop.
AdventOfCode Day10 challenge
"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