Created
January 21, 2016 07:44
-
-
Save skipme/a2e9f5cb6f6c7f9084b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function toxy(num){ | |
var strxy="x"; | |
for(var i=0;i<num;i++){ | |
strxy+="y"; | |
} | |
strxy+="z"; | |
return strxy; | |
} | |
function printxytonum(strxy) | |
{ | |
var result = ""; | |
var cur = [0]; | |
var curidx = 0; | |
for(var i = 0;i<strxy.length;i++) | |
{ | |
if(strxy[i] === 'x')// event a | |
cur[0]=0; | |
else if(strxy[i] === 'y')// event b | |
{ | |
for(var x = 0;true;x++) | |
{ | |
if(cur[x]<9) | |
{ | |
cur[x]++; | |
break; | |
}else{ | |
cur[x]=0; | |
if(cur[x+1] === undefined) | |
cur[x+1]=0; | |
} | |
} | |
} | |
} | |
for(var i = cur.length-1;i>=0;i--){ | |
result += cur[i].toString(); | |
} | |
return result; | |
} | |
var xystr = toxy(4888461); | |
console.log(//xystr, | |
'\n',printxytonum(xystr)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment