Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
|||
fcn permute(seq)
|
||||
{
|
||||
insertEverywhere := fcn(x,list){ //(x,(a,b))-->((x,a,b),(a,x,b),(a,b,x))
|
||||
(0).pump(list.len()+1,List,'wrap(n){list[0,n].extend(x,list[n,*]) })};
|
||||
insertEverywhereB := fcn(x,t){ //--> insertEverywhere().reverse()
|
||||
[t.len()..-1,-1].pump(t.len()+1,List,'wrap(n){t[0,n].extend(x,t[n,*])})};
|
||||
|
||||
seq.reduce('wrap(items,x){
|
||||
f := Utils.Helpers.cycle(insertEverywhereB,insertEverywhere);
|
||||
items.pump(List,'wrap(item){f.next()(x,item)},
|
||||
T.fp(Void.Write,Void.Write));
|
||||
},T(T));
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
p := permute(T(1,2,3));
|
||||
p.println();
|
||||
|
||||
p := permute([1..4]);
|
||||
p.len().println();
|
||||
p.toString(*).println()
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
fcn [private] _permuteW(seq){ // lazy version
|
||||
N:=seq.len(); NM1:=N-1;
|
||||
ds:=(0).pump(N,List,T(Void,-1)).copy(); ds[0]=0; // direction to move e: -1,0,1
|
||||
es:=(0).pump(N,List).copy(); // enumerate seq
|
||||
|
||||
while(1) {
|
||||
vm.yield(es.pump(List,seq.__sGet));
|
||||
|
||||
// find biggest e with d!=0
|
||||
reg i=Void, c=-1;
|
||||
foreach n in (N){ if(ds[n] and es[n]>c) { c=es[n]; i=n; } }
|
||||
if(Void==i) return();
|
||||
|
||||
d:=ds[i]; j:=i+d;
|
||||
es.swap(i,j); ds.swap(i,j); // d tracks e
|
||||
if(j==NM1 or j==0 or es[j+d]>c) ds[j]=0;
|
||||
foreach e in (N){ if(es[e]>c) ds[e]=(i-e).sign }
|
||||
}
|
||||
}
|
||||
|
||||
fcn permuteW(seq) { Utils.Generator(_permuteW,seq) }
|
||||
|
|
@ -0,0 +1 @@
|
|||
foreach p in (permuteW(T("a","b","c"))){ println(p) }
|
||||
Loading…
Add table
Add a link
Reference in a new issue