Skip to content

Instantly share code, notes, and snippets.

@skipme
Created January 21, 2016 07:44
Show Gist options
  • Save skipme/a2e9f5cb6f6c7f9084b4 to your computer and use it in GitHub Desktop.
Save skipme/a2e9f5cb6f6c7f9084b4 to your computer and use it in GitHub Desktop.
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