summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AufgabeFFP7.hs42
1 files changed, 38 insertions, 4 deletions
diff --git a/AufgabeFFP7.hs b/AufgabeFFP7.hs
index 9d05db3..9337010 100644
--- a/AufgabeFFP7.hs
+++ b/AufgabeFFP7.hs
@@ -1,6 +1,8 @@
1module AufgabeFFP7 1module AufgabeFFP7
2where 2where
3 3
4import List hiding ((\\))
5
4type Buffer = (Int, String) 6type Buffer = (Int, String)
5 7
6-- the empty buffer 8-- the empty buffer
@@ -59,10 +61,42 @@ type BufferI = (String, String)
59 61
60-------------------------------------------------------------------------------- 62--------------------------------------------------------------------------------
61 63
62--TODO ssfn :: 64-- from slide 154
63--TODO sap :: 65divideAndConquer :: (p -> Bool) -> (p -> s) -> (p -> [p]) -> (p -> [s] -> s) -> p -> s
64--TODO minfree :: 66divideAndConquer indiv solve divide combine initPb = dAC initPb
65--TODO removeDuplicates :: 67 where
68 dAC pb
69 | indiv pb = solve pb
70 | otherwise = combine pb (map dAC (divide pb))
71
72-- from slide 156
73quickSort :: Ord a => [a] -> [a]
74quickSort lst = divideAndConquer indiv solve divide combine lst
75 where
76 indiv ls = length ls <= 1
77 solve = id
78 divide (l:ls) = [[ x | x <- ls, x <= l], [ x | x <- ls, x > l] ]
79 combine (l:_) [l1,l2] = l1 ++ [l] ++ l2
80
81removeDuplicates :: [Integer] -> [Integer]
82removeDuplicates xs = nub xs
83
84-- from slide 245
85ssfn :: [Integer] -> Integer
86ssfn = (sap 0) . removeDuplicates . quickSort
87
88sap :: Integer -> [Integer] -> Integer
89sap n [] = 0
90sap n (x:xs)
91 | n /= x = n
92 | otherwise = sap (n+1) xs
93
94-- from slide 247
95(\\) :: Eq a => [a] -> [a] -> [a]
96xs \\ ys = filter (\x -> x `notElem` ys) xs
97
98minfree :: [Int] -> Int
99minfree xs = head ([0..] \\ xs)
66 100
67-------------------------------------------------------------------------------- 101--------------------------------------------------------------------------------
68 102