diff options
| author | totycro <totycro@unknown-horizons.org> | 2012-05-29 21:04:14 +0200 |
|---|---|---|
| committer | totycro <totycro@unknown-horizons.org> | 2012-05-29 21:04:14 +0200 |
| commit | 036885a5375d0eada3b03d200fcc6353985a624b (patch) | |
| tree | 2085847976c7ac9c60a9cbb44737fa5a2a0fbc9a /AufgabeFFP8.hs | |
| parent | b9056493bf23c24a60ce0d259aa648033233e746 (diff) | |
| download | ffp-036885a5375d0eada3b03d200fcc6353985a624b.tar.gz ffp-036885a5375d0eada3b03d200fcc6353985a624b.tar.bz2 ffp-036885a5375d0eada3b03d200fcc6353985a624b.zip | |
minfree divide & conquer von folien
Diffstat (limited to 'AufgabeFFP8.hs')
| -rw-r--r-- | AufgabeFFP8.hs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/AufgabeFFP8.hs b/AufgabeFFP8.hs index 298898b..e667654 100644 --- a/AufgabeFFP8.hs +++ b/AufgabeFFP8.hs | |||
| @@ -47,13 +47,41 @@ search_countlist = length . takeWhile (/= 0) . elems | |||
| 47 | 47 | ||
| 48 | -- basic divide-and-conquer | 48 | -- basic divide-and-conquer |
| 49 | minfree_b :: [Int] -> Int | 49 | minfree_b :: [Int] -> Int |
| 50 | minfree_b xs = if (null ([0..b-1] \\ us)) | ||
| 51 | then (head ([b..] \\ vs)) | ||
| 52 | else (head ([0..] \\ us)) | ||
| 53 | where | ||
| 54 | (us, vs) = partition (<b) xs | ||
| 55 | b = 1 + (length xs) `div` 2 | ||
| 50 | 56 | ||
| 51 | -- refined divide-and-conquer | 57 | -- refined divide-and-conquer |
| 52 | --minfree_r :: [Int] -> Int | 58 | minfree_r :: [Int] -> Int |
| 59 | minfree_r xs = minfrom 0 xs | ||
| 60 | |||
| 61 | minfrom :: Int -> [Int] -> Int | ||
| 62 | minfrom a xs | ||
| 63 | | null xs = a | ||
| 64 | | length us == b-a = minfrom b vs | ||
| 65 | | otherwise = minfrom a us | ||
| 66 | where | ||
| 67 | (us, vs) = partition (<b) xs | ||
| 68 | b = a + 1 + (length xs) `div` 2 | ||
| 53 | 69 | ||
| 54 | -- optimised divide-and-conquer | 70 | -- optimised divide-and-conquer |
| 55 | --minfree_o :: [Int] -> Int | 71 | minfree_o :: [Int] -> Int |
| 56 | -- | 72 | minfree_o xs = minfrom_o 0 (length xs, xs) |
| 73 | |||
| 74 | minfrom_o :: Int -> (Int, [Int]) -> Int | ||
| 75 | minfrom_o a (n, xs) | ||
| 76 | | n == 0 = a | ||
| 77 | | m == b-a = minfrom_o b (n-m, vs) | ||
| 78 | | otherwise = minfrom_o a (m, us) | ||
| 79 | where | ||
| 80 | (us, vs) = partition (<b) xs | ||
| 81 | b = a + 1 + n `div` 2 | ||
| 82 | m = length us | ||
| 83 | |||
| 84 | |||
| 57 | -- basic divide-and-conquer mittels higher order function | 85 | -- basic divide-and-conquer mittels higher order function |
| 58 | --minfree_bhof :: [Int] -> Int | 86 | --minfree_bhof :: [Int] -> Int |
| 59 | 87 | ||
