Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,17 @@
|
|||
fcn longestSequence(ns){ // based on Patience sorting
|
||||
piles:=L();
|
||||
backPtr:='wrap(np){ return(np-1,if(np) piles[np-1].len()-1 else -1) }; // maybe (-1,-1)
|
||||
foreach n in (ns){ newPile:=True; // create list of sorted lists
|
||||
foreach e,p in (piles.enumerate()){
|
||||
if(n<p[-1][0]){
|
||||
p.del(1,-1) // only need the first and last elements
|
||||
.append(T(n,backPtr(e))); newPile=False;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(newPile) piles.append(L(T(n,backPtr(piles.len()))));
|
||||
}
|
||||
reg r=L(),p=-1,n=0;
|
||||
do{ n,p=piles[p][n]; r.write(n); p,n=p; }while(p!=-1);
|
||||
r.reverse()
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
foreach ns in (T(T(1),T(3,2,6,4,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")){
|
||||
s:=longestSequence(ns);
|
||||
println(s.len(),": ",s," from ",ns);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue