RosettaCodeData/Task/Longest-increasing-subsequence/Deja-Vu/longest-increasing-subsequence.djv
2015-02-20 09:02:09 -05:00

25 lines
543 B
Text

in-pair:
if = :nil dup:
false drop
else:
@in-pair &> swap &< dup
get-last lst:
get-from lst -- len lst
lis-sub pile i di:
for j range 0 -- len pile:
local :pj get-from pile j
if > &< get-last pj di:
push-to pj & di if j get-last get-from pile -- j :nil
return
push-to pile [ & di get-last get-last pile ]
lis d:
local :pile [ [ & get-from d 0 :nil ] ]
for i range 1 -- len d:
lis-sub pile i get-from d i
[ for in-pair get-last get-last pile ]
!. lis [ 3 2 6 4 5 1 ]
!. lis [ 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 ]