Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Nonoblock/Zkl/nonoblock-1.zkl
Normal file
33
Task/Nonoblock/Zkl/nonoblock-1.zkl
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
fcn nonoblocks(blocks,cells){
|
||||
if(not blocks or blocks[0]==0) vm.yield( T(T(0,0)) );
|
||||
else{
|
||||
if(not ( blocks.sum(0) + blocks.len() -1<=cells ))
|
||||
throw(Exception.AssertionError("Those blocks will not fit in those cells"));
|
||||
blength,brest:=blocks[0], blocks[1,*]; # Deal with the first block of length
|
||||
minspace4rest:=brest.reduce('+(1),0); # The other blocks need space
|
||||
# Slide the start position from left to max RH index allowing for other blocks.
|
||||
foreach bpos in (cells - minspace4rest - blength +1){
|
||||
if(not brest) # No other blocks to the right so just yield this one.
|
||||
vm.yield(T(T(bpos,blength)));
|
||||
else{
|
||||
# More blocks to the right so create a *sub-problem* of placing
|
||||
# the brest blocks in the cells one space to the right of the RHS of
|
||||
# this block.
|
||||
offset:=bpos + blength +1;
|
||||
# recursive call to nonoblocks yields multiple sub-positions
|
||||
foreach subpos in (Utils.Generator(nonoblocks,brest,cells - offset)){
|
||||
# Remove the offset from sub block positions
|
||||
rest:=subpos.pump(List,'wrap([(bp,bl)]){ T(offset + bp, bl) });
|
||||
# Yield this block plus sub blocks positions
|
||||
vm.yield(T( T(bpos,blength) ).extend(rest) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# Pretty print each run of blocks with a different letter for each block of filled cells
|
||||
fcn pblock(vec,cells){
|
||||
vector,ch:=cells.pump(List(),"_".copy), ["A".."Z"];
|
||||
vec.apply2('wrap([(a,b)]){ a.walker(b).pump(Void,vector.set.fp1(ch.next())) });
|
||||
String("|",vector.concat("|"),"|");
|
||||
}
|
||||
11
Task/Nonoblock/Zkl/nonoblock-2.zkl
Normal file
11
Task/Nonoblock/Zkl/nonoblock-2.zkl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
foreach blocks,cells in (T( T(T(2,1),5), T(T,5), T(T(8),10), T(T(2,3,2,3),15),
|
||||
T(T(2,3),5) )){
|
||||
println("\nConfiguration:\n %s # %d cells and %s blocks"
|
||||
.fmt(pblock(T,cells),cells,blocks));
|
||||
println(" Possibilities:");
|
||||
Utils.Generator(nonoblocks,blocks,cells).reduce('wrap(n,vector){
|
||||
println(" ",pblock(vector,cells));
|
||||
n+1
|
||||
},0)
|
||||
: println(" A total of %d possible configurations.".fmt(_));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue