Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,17 @@
|
|||
fcn patienceSort(ns){
|
||||
piles:=L();
|
||||
foreach n in (ns){ newPile:=True; // create list of sorted lists
|
||||
foreach p in (piles){
|
||||
if(n>=p[-1]) { p.append(n); newPile=False; break; }
|
||||
}
|
||||
if(newPile)piles.append(L(n));
|
||||
}
|
||||
// merge sort the piles
|
||||
r:=Sink(List); while(piles){
|
||||
mins:=piles.apply("get",0).enumerate();
|
||||
min :=mins.reduce(fcn(a,b){ (a[1]<b[1]) and a or b },mins[0])[0];
|
||||
r.write(piles[min].pop(0));
|
||||
if(not piles[min]) piles.del(min);
|
||||
}
|
||||
r.close();
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
T(T(3,2,6,4,3,5,1),
|
||||
T(4,65,2,-31,0,99,83,782,1),
|
||||
T(0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15),
|
||||
"foobar")
|
||||
.pump(Console.println,patienceSort);
|
||||
Loading…
Add table
Add a link
Reference in a new issue