Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
fcn binomial(n,k){ (1).reduce(k,fcn(p,i,n){ p*(n-i+1)/i },1,n) }
|
||||
fcn pascal_upp(n){ [[(i,j); n; n; '{ binomial(j,i) }]]:toMatrix(_) } // [[..]] is list comprehension
|
||||
fcn pascal_low(n){ [[(i,j); n; n; binomial]]:toMatrix(_) }
|
||||
fcn pascal_sym(n){ [[(i,j); n; n; '{ binomial(i+j,i) }]]:toMatrix(_) }
|
||||
fcn toMatrix(ns){ // turn a string of numbers into a square matrix (list of lists)
|
||||
cols:=ns.len().toFloat().sqrt().toInt();
|
||||
ns.pump(List,T(Void.Read,cols-1),List.create)
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fcn prettyPrint(m){ // m is a list of lists
|
||||
fmt:=("%3d "*m.len() + "\n").fmt;
|
||||
m.pump(String,'wrap(col){ fmt(col.xplode()) });
|
||||
}
|
||||
const N=5;
|
||||
println("Upper:\n", pascal_upp(N):prettyPrint(_));
|
||||
println("Lower:\n", pascal_low(N):prettyPrint(_));
|
||||
println("Symmetric:\n",pascal_sym(N):prettyPrint(_));
|
||||
Loading…
Add table
Add a link
Reference in a new issue