Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
const MAX = 12;
|
||||
var super=Data(), pos, cnt; // global state, ick
|
||||
|
||||
fcn fact_sum(n){ // -->1! + 2! + ... + n!
|
||||
[1..n].reduce(fcn(s,n){ s + [2..n].reduce('*,1) },0)
|
||||
}
|
||||
|
||||
fcn r(n){
|
||||
if (not n) return(0);
|
||||
|
||||
c := super[pos - n];
|
||||
if (not (cnt[n]-=1)){
|
||||
cnt[n] = n;
|
||||
if (not r(n-1)) return(0);
|
||||
}
|
||||
super[pos] = c; pos+=1;
|
||||
1
|
||||
}
|
||||
|
||||
fcn superperm(n){
|
||||
pos = n;
|
||||
len := fact_sum(n);
|
||||
super.fill(0,len); // this is pretty close to recalloc()
|
||||
|
||||
cnt = (n+1).pump(List()); //-->(0,1,2,3,..n)
|
||||
foreach i in (n){ super[i] = i + 0x31; } //-->"1" ... "123456789:;"
|
||||
while (r(n)){}
|
||||
}
|
||||
|
||||
foreach n in (MAX){
|
||||
superperm(n);
|
||||
print("superperm(%2d) len = %d".fmt(n,super.len()));
|
||||
// uncomment next line to see the string itself
|
||||
//print(": %s".fmt(super.text));
|
||||
println();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue