function myFunction() {
var a=new Array();
var x=new Array();
var y=new Array();
var dir_x=new Array();
var dir_y=new Array();
var route=new Array();
var number_route=new Array();
tx=0;
for(s=1;s<6;s++){
for(sx=1;sx<6;sx++){
tx=tx+1;
x[tx]=sx;
y[tx]=s;
}}
dir_x[1]=1;
dir_y[1]=0;
dir_x[2]=-1;
dir_y[2]=0;
dir_x[3]=0;
dir_y[3]=1;
dir_x[4]=0;
dir_y[4]=-1;
for(s=1;s<26;s++){
route[s]=new Array();
}
for(s=1;s<26;s++){
n=0;
for(sx=1;sx<5;sx++){
x1=x[s]+dir_x[sx];
y1=y[s]+dir_y[sx];
sxs=0;
for(tx=1;tx<26;tx++){
h=0;
if(x1==x[tx])h=h+1;
if(y1==y[tx])h=h+1;
if(h==2)sxs=tx;
}
if(sxs>0)n=n+1;
if(sxs>0)route[s][n]=sxs;
}
number_route[s]=n;
}
for(s=1;s<6;s++){
a[s]=s;
}
for(tr=1;tr<100;tr++){
for(s=1;s<6;s++){
n=a[s]
z1=number_route[n]*Math.random();
z2=Math.floor(z1)+1;
a[s]=route[n][z2];
}
}
Logger.log(a[1]);
id="1GQYvMgyX1jiwFN12RmKCdEQJVPxzDADXmAuZLEVyO0Q";
ex = SpreadsheetApp.openById(id);
var shx = ex.getSheetByName("data");
for(s=1;s<6;s++){
shx.setRowHeight(s, 50);
shx.setColumnWidth(s,50);
}
var colx=new Array();
for(s=0;s<5;s++){
colx[s]=new Array();
}
for(s=0;s<5;s++){
for(sx=0;sx<5;sx++){
colx[s][sx]="blue";
}}
for(s=1;s<6;s++){
sx=a[s];
x1=x[sx];
y1=y[sx];
colx[y1-1][x1-1]="red";
}
shx.getRange(1, 1,5,5).setBackgrounds(colx)
}
最終更新:2017年08月10日 00:09