How to resolve the algorithm Longest increasing subsequence step by step in the Clojure programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Longest increasing subsequence step by step in the Clojure programming language

Table of Contents

Problem Statement

Calculate and show here a longest increasing subsequence of the list: And of the list: Note that a list may have more than one subsequence that is of the maximum length.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Longest increasing subsequence step by step in the Clojure programming language

Source code in the clojure programming language

(defn place [piles card]
  (let [[les gts] (->> piles (split-with #(<= (ffirst %) card)))
        newelem (cons card (->> les last first))
        modpile (cons newelem (first gts))]
    (concat les (cons modpile (rest gts)))))

(defn a-longest [cards]
  (let [piles (reduce place '() cards)]
    (->> piles last first reverse)))

(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]))


(2 4 5)
(0 2 6 9 11 15)


  

You may also check:How to resolve the algorithm Queue/Definition step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Input loop step by step in the Batch File programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the Miranda programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the mIRC Scripting Language programming language
You may also check:How to resolve the algorithm Comma quibbling step by step in the FutureBasic programming language