summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Wisniowski <matthias.wisniowski@gmail.com>2012-05-30 02:04:00 +0200
committerMatthias Wisniowski <matthias.wisniowski@gmail.com>2012-05-30 02:04:00 +0200
commit46071eee81e180c0f9c2e413f5bec6fd613a7576 (patch)
treefae3a11f9878d2ee5271f9a82dcc1ee18da112d1
parent205683f9690ff9231247ed18696ec64559eac393 (diff)
downloadffp-46071eee81e180c0f9c2e413f5bec6fd613a7576.tar.gz
ffp-46071eee81e180c0f9c2e413f5bec6fd613a7576.tar.bz2
ffp-46071eee81e180c0f9c2e413f5bec6fd613a7576.zip
minfree_ohof
-rw-r--r--AufgabeFFP8.hs26
1 files changed, 25 insertions, 1 deletions
diff --git a/AufgabeFFP8.hs b/AufgabeFFP8.hs
index fffc717..89c3a66 100644
--- a/AufgabeFFP8.hs
+++ b/AufgabeFFP8.hs
@@ -121,7 +121,7 @@ r_indiv (a, []) = True
121r_indiv _ = False 121r_indiv _ = False
122 122
123r_solve :: (Int, [Int]) -> Int 123r_solve :: (Int, [Int]) -> Int
124r_solve (a, _) = a 124r_solve (a, []) = a
125 125
126r_divide :: (Int, [Int]) -> [(Int, [Int])] 126r_divide :: (Int, [Int]) -> [(Int, [Int])]
127r_divide (a, xs) 127r_divide (a, xs)
@@ -137,6 +137,30 @@ r_combine _ (a:[]) = a
137minfree_rhof :: [Int] -> Int 137minfree_rhof :: [Int] -> Int
138minfree_rhof xs = divideAndConquer r_indiv r_solve r_divide r_combine (0, xs) 138minfree_rhof xs = divideAndConquer r_indiv r_solve r_divide r_combine (0, xs)
139 139
140-- minfree optimized daq higher order
141
142o_indiv :: (Int, Int, [Int]) -> Bool
143o_indiv (a, 0, []) = True
144o_indiv _ = False
145
146o_solve :: (Int, Int, [Int]) -> Int
147o_solve (a, 0, []) = a
148
149o_divide :: (Int, Int, [Int]) -> [(Int, Int, [Int])]
150o_divide (a, n, xs)
151 | ls == b-a = [(b, length bigger, bigger)]
152 | otherwise = [(a, ls, smaller)]
153 where
154 b = a + 1 + n `div` 2
155 (smaller, bigger) = partition (<b) xs
156 ls = length smaller
157
158o_combine :: (Int, Int, [Int]) -> [Int] -> Int
159o_combine _ (a:[]) = a
160
161minfree_ohof :: [Int] -> Int
162minfree_ohof xs = divideAndConquer o_indiv o_solve o_divide o_combine (0, length xs, xs)
163
140-- QuickCheck part 164-- QuickCheck part
141 165
142functions = [ minfree_bv, minfree_chl, minfree_col, 166functions = [ minfree_bv, minfree_chl, minfree_col,