Skip to content

Instantly share code, notes, and snippets.

@hiroshi-maybe
Created February 14, 2012 16:52
Show Gist options
  • Save hiroshi-maybe/1828081 to your computer and use it in GitHub Desktop.
Save hiroshi-maybe/1828081 to your computer and use it in GitHub Desktop.
Google Employment Exam
<!DOCTYPE HTML5>
<meta charset=\"UTF-8\"/>
<html>
<title>Google Employment Exam</title>
<body>
1<br/>
11<br/>
21<br/>
1211<br/>
111221<br/>
?<br/>
<br/>
Answer:<br/>
<script>
(function(depth) {
var init = ['1'];
document.write(init[0]+"<br/>");
(function gi(array, cdepth) {
var i=0, current=array[0],num=0,res=[],j=0;
for (; i<array.length; i+=1) {
if(array[i]==current) {
num+=1;
} else {
res.push(num);
res.push(current);
current = array[i];
num = 1;
}
}
res.push(num);
res.push(current);
document.write(res.join("")+"<br/>");
if (cdepth<=depth) {
gi(res, cdepth+1);
}
})(init, 1);
})(4);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment