September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,19 @@
|
|||
fcn subFact(n){
|
||||
if(n==0) return(1);
|
||||
if(n==1) return(0);
|
||||
(n-1)*(self.fcn(n-1) + self.fcn(n-2));
|
||||
}
|
||||
|
||||
fcn derangements(n){
|
||||
// All deranged permutations of the integers 0..n-1 inclusive
|
||||
enum:=[0..n-1].pump(List);
|
||||
Utils.Helpers.permuteW(enum).filter('wrap(perm){
|
||||
perm.zipWith('==,enum).sum(0) == 0
|
||||
});
|
||||
}
|
||||
fcn derangers(n){ // just count # of derangements
|
||||
enum:=[0..n-1].pump(List);
|
||||
Utils.Helpers.permuteW(enum).reduce('wrap(sum,perm){
|
||||
sum + (perm.zipWith('==,enum).sum(0) == 0)
|
||||
},0);
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
println("Derangements of 0,1,2,3:\n",derangements(4));
|
||||
println("\nTable of n vs counted vs calculated derangements:");
|
||||
foreach n in (10){
|
||||
println("%2d %-6d %-6d".fmt(n, derangers(n), subFact(n)));
|
||||
}
|
||||
|
||||
n:=20; println("\n!%d = %d".fmt(n, subFact(n)));
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fcn derangements(n){ //-->Walker
|
||||
enum:=[0..n-1].pump(List);
|
||||
Utils.Helpers.permuteW(enum).tweak('wrap(perm){
|
||||
if(perm.zipWith('==,enum).sum(0)) Void.Skip
|
||||
else perm
|
||||
});
|
||||
}
|
||||
fcn derangers(n){ // just count # of derangements, w/o saving them
|
||||
derangements(n).reduce('+.fpM("10-",1),0); // ignore perm --> '+(1,sum)...
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
foreach d in (derangements(4)){ println(d) }
|
||||
//rest of test code remains the same
|
||||
Loading…
Add table
Add a link
Reference in a new issue