Created
February 14, 2012 16:52
-
-
Save hiroshi-maybe/1828081 to your computer and use it in GitHub Desktop.
Google Employment Exam
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
<!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