-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20150416.hs
49 lines (35 loc) · 1.13 KB
/
20150416.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
--TRABALHO 8
listPartitioner :: Ord a => Num a => [a] -> ([a] -> [[a]])
listPartitioner l = func
where func t = [x | x <- (aux (quick l) t) , x /= []];
aux o lis
|o == [] = [lis]
|otherwise = [fst(splitList lis (head o))] ++ aux (tail o) (snd (splitList lis (head o)))
splitList :: Ord t => [t] -> t -> ([t], [t])
splitList l n= ([x | x <- l, x <= n], [x | x <- l, x > n])
quick[] = []
quick(h:t) = quick[x | x <- t, x <= h] ++ h:quick[y|y<-t, y>h]
---QUESTÕES DA AULA
func :: (t -> u -> v) -> (u -> t -> v)
func f = \p1 p2 -> f (p2) (p1)
firsts :: ([(t, t)] -> [t])
firsts = \x -> [fst n| n <- x ]
newList :: ([[n]] -> Int -> [[n]])
newList = \x n-> [y | y <- x, (length y) > n]
removeDup :: Ord n => Eq n => ([[n]] -> [n])
removeDup = \x -> aux x
where aux n = remove (quick (fun n));
fun n
|n == [] = []
|otherwise = (head n) ++ fun (tail n)
remove :: Eq n => [n] -> [n]
remove l
|l == [] = []
|tail l == [] = l
|head l == head(tail l) = remove (tail l)
|otherwise = [head l] ++ remove (tail l)
--map.foldr
--aplição parcial
sumElem x l = map (+x) l
--greaterElem :: Ord => [n] -> n
--greaterElem l =