Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If all your lists are increasing (like they are in your example) the following should work (not a beauty as I'm a Haskell-newbie; comments about how to improve are very welcome):</p> <pre><code>import Control.Arrow (first, second) compFreq ls = cF [] [] ls where cF rs cs ls | all null ls = rs | otherwise = cF (rs++rs') (cs'' ++ c ++ cs') ls' where m = minimum $ map head $ filter (not . null) ls ls' = map (\l -&gt; if null l || m &lt; head l then l else tail l) ls is = map snd $ filter ((==m) . head . fst) $ filter (not . null . fst) $ zip ls [0,1..] c = if atLeastTwo is then [([m], is)] else [] fs = filter (\(vs, is') -&gt; atLeastTwo $ combine is is') cs cs' = map (\(vs, is') -&gt; (vs++[m], combine is is')) fs cs'' = map (second (filter (not . (`elem` is)))) cs rs' = filter ok cs' combine _ [] = [] combine [] _ = [] combine (i:is) (i':is') | i&lt;i' = combine is (i':is') | i&gt;i' = combine (i:is) is' | i==i' = i:combine is is' atLeastTwo = not . null . drop 1 ok (js, ts) = atLeastTwo js &amp;&amp; atLeastTwo ts </code></pre> <p>The idea is to process the lists by looking always at the minimal value m, which is removed from all lists to get ls'. The list of indices is tells where m was removed. The inner working function cF has two extra parameters: the list rs of results up to now and the list cs of current subsequences. The minimal value starts a new subsequence c if it occurs at least twice. cs' are subsequences which end with m and cs'' are those without m. The new results rs' all contain m as last element.</p> <p>The output for your example is</p> <pre><code>[([1,2],[0,3]),([2,3],[0,1,3]),([1,2,3],[0,3]),([3,5],[0,1,2,4]),([2,3,5],[0,1]),([5,7],[0,2,4]),([3,5,7],[0,2,4]),([7,9],[2,3])] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload