-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab1.hs
18 lines (17 loc) · 1.18 KB
/
lab1.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import Data.List
kmaxsubunique :: [Int] -> Int -> [(Int,Int,Int)]
kmaxsubunique x k = kmaxsub (rmd x) k
where rmd [] = []
rmd (x:y) = x:[i | i <- rmd y , i /= x] -- Remove duplicates
kmaxsub x k = take k( -- Get the first k triples
reverse( -- Reverse the list
sort( -- Sort the list
[(v,i,j) | -- Construct the triples
n <- (tails x) `union` (inits x), -- Get all continuous subsequences
let v = sum n -- Sum of the subsequence
i = head(elemIndices (head n) x)+1 -- Find the index of the first element in the subsequence in the original list
j = head(elemIndices (last n) x)+1 -- Find the index of the last element in the subsequence in the original list
]
)
)
)