diff options
| author | Matthias Wisniowski <matthias.wisniowski@gmail.com> | 2012-05-30 02:04:00 +0200 |
|---|---|---|
| committer | Matthias Wisniowski <matthias.wisniowski@gmail.com> | 2012-05-30 02:04:00 +0200 |
| commit | 46071eee81e180c0f9c2e413f5bec6fd613a7576 (patch) | |
| tree | fae3a11f9878d2ee5271f9a82dcc1ee18da112d1 | |
| parent | 205683f9690ff9231247ed18696ec64559eac393 (diff) | |
| download | ffp-46071eee81e180c0f9c2e413f5bec6fd613a7576.tar.gz ffp-46071eee81e180c0f9c2e413f5bec6fd613a7576.tar.bz2 ffp-46071eee81e180c0f9c2e413f5bec6fd613a7576.zip | |
minfree_ohof
| -rw-r--r-- | AufgabeFFP8.hs | 26 |
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 | |||
| 121 | r_indiv _ = False | 121 | r_indiv _ = False |
| 122 | 122 | ||
| 123 | r_solve :: (Int, [Int]) -> Int | 123 | r_solve :: (Int, [Int]) -> Int |
| 124 | r_solve (a, _) = a | 124 | r_solve (a, []) = a |
| 125 | 125 | ||
| 126 | r_divide :: (Int, [Int]) -> [(Int, [Int])] | 126 | r_divide :: (Int, [Int]) -> [(Int, [Int])] |
| 127 | r_divide (a, xs) | 127 | r_divide (a, xs) |
| @@ -137,6 +137,30 @@ r_combine _ (a:[]) = a | |||
| 137 | minfree_rhof :: [Int] -> Int | 137 | minfree_rhof :: [Int] -> Int |
| 138 | minfree_rhof xs = divideAndConquer r_indiv r_solve r_divide r_combine (0, xs) | 138 | minfree_rhof xs = divideAndConquer r_indiv r_solve r_divide r_combine (0, xs) |
| 139 | 139 | ||
| 140 | -- minfree optimized daq higher order | ||
| 141 | |||
| 142 | o_indiv :: (Int, Int, [Int]) -> Bool | ||
| 143 | o_indiv (a, 0, []) = True | ||
| 144 | o_indiv _ = False | ||
| 145 | |||
| 146 | o_solve :: (Int, Int, [Int]) -> Int | ||
| 147 | o_solve (a, 0, []) = a | ||
| 148 | |||
| 149 | o_divide :: (Int, Int, [Int]) -> [(Int, Int, [Int])] | ||
| 150 | o_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 | |||
| 158 | o_combine :: (Int, Int, [Int]) -> [Int] -> Int | ||
| 159 | o_combine _ (a:[]) = a | ||
| 160 | |||
| 161 | minfree_ohof :: [Int] -> Int | ||
| 162 | minfree_ohof xs = divideAndConquer o_indiv o_solve o_divide o_combine (0, length xs, xs) | ||
| 163 | |||
| 140 | -- QuickCheck part | 164 | -- QuickCheck part |
| 141 | 165 | ||
| 142 | functions = [ minfree_bv, minfree_chl, minfree_col, | 166 | functions = [ minfree_bv, minfree_chl, minfree_col, |
