Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Cut-a-rectangle/Zkl/cut-a-rectangle-1.zkl
Normal file
34
Task/Cut-a-rectangle/Zkl/cut-a-rectangle-1.zkl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
fcn cut_it(h,w){
|
||||
if(h.isOdd){
|
||||
if(w.isOdd) return(0);
|
||||
t,h,w=h,w,t; // swap w,h: a,b=c,d --> a=c; b=d; so need a tmp
|
||||
}
|
||||
if(w==1) return(1);
|
||||
|
||||
nxt :=T(T(w+1, 1,0), T(-w-1, -1,0), T(-1, 0,-1), T(1, 0,1)); #[next, dy,dx]
|
||||
blen:=(h + 1)*(w + 1) - 1;
|
||||
grid:=(blen + 1).pump(List(),False); //-->L(False,False...)
|
||||
|
||||
walk:='wrap(y,x){ // lambda closure
|
||||
if(y==0 or y==h or x==0 or x==w) return(1);
|
||||
count,t:=0,y*(w + 1) + x;
|
||||
grid[t]=grid[blen - t]=True;
|
||||
foreach nt,dy,dx in (nxt){
|
||||
if(not grid[t + nt]) count+=self.fcn(y + dy, x + dx,vm.pasteArgs(2));
|
||||
}
|
||||
grid[t]=grid[blen - t]=False;
|
||||
count
|
||||
};
|
||||
|
||||
t:=h/2*(w + 1) + w/2;
|
||||
if(w.isOdd){
|
||||
grid[t]=grid[t + 1]=True;
|
||||
count:=walk(h/2, w/2 - 1);
|
||||
count + walk(h/2 - 1, w/2)*2;
|
||||
}else{
|
||||
grid[t]=True;
|
||||
count:=walk(h/2, w/2 - 1);
|
||||
if(h==w) return(count*2);
|
||||
count + walk(h/2 - 1, w/2);
|
||||
}
|
||||
}
|
||||
3
Task/Cut-a-rectangle/Zkl/cut-a-rectangle-2.zkl
Normal file
3
Task/Cut-a-rectangle/Zkl/cut-a-rectangle-2.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
foreach w,h in ([1..9],[1..w]){
|
||||
if((w*h).isEven) println("%d x %d: %d".fmt(w, h, cut_it(w,h)));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue