Longest increasing subsequence: Difference between revisions

m
m ({{out}})
Line 159:
 
=={{header|Clojure}}==
Implementation using the Patience Sort approach.
Implementation using the Patience Sort approach. The elements (''newelem'') put on a pile combine the "card" with a reference to the top of the previous stack, as per the algorithm. The combination is done using ''cons'', so what gets put on a pile is a list -- a descending subsequence.
The combination is done using ''cons'', so what gets put on a pile is a list -- a descending subsequence.
 
<lang Clojure>(defn place [piles card]
Line 173 ⟶ 175:
(println (a-longest [3 2 6 4 5 1]))
(println (a-longest [0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15]))</lang>
{{out}}
Output:
<lang>(2 4 5)
(0 2 6 9 11 15)</lang>
Anonymous user