diff options
| -rw-r--r-- | AufgabeFFP8.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/AufgabeFFP8.hs b/AufgabeFFP8.hs index e667654..f6d9bfd 100644 --- a/AufgabeFFP8.hs +++ b/AufgabeFFP8.hs | |||
| @@ -82,6 +82,16 @@ minfrom_o a (n, xs) | |||
| 82 | m = length us | 82 | m = length us |
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | -- from slide 154 | ||
| 86 | divideAndConquer :: (p -> Bool) -> (p -> s) -> (p -> [p]) -> (p -> [s] -> s) -> p -> s | ||
| 87 | divideAndConquer indiv solve divide combine initPb = dAC initPb | ||
| 88 | where | ||
| 89 | dAC pb | ||
| 90 | | indiv pb = solve pb | ||
| 91 | | otherwise = combine pb (map dAC (divide pb)) | ||
| 92 | |||
| 93 | |||
| 94 | |||
| 85 | -- basic divide-and-conquer mittels higher order function | 95 | -- basic divide-and-conquer mittels higher order function |
| 86 | --minfree_bhof :: [Int] -> Int | 96 | --minfree_bhof :: [Int] -> Int |
| 87 | 97 | ||
| @@ -94,3 +104,32 @@ minfrom_o a (n, xs) | |||
| 94 | 104 | ||
| 95 | 105 | ||
| 96 | -- QuickCheck part | 106 | -- QuickCheck part |
| 107 | |||
| 108 | functions = [ minfree_bv, minfree_chl, minfree_col, | ||
| 109 | minfree_b, minfree_r, minfree_o ] | ||
| 110 | |||
| 111 | -- calc values of all function | ||
| 112 | calc_all :: [Int] -> [Int] | ||
| 113 | calc_all xs = [ f xs | f <- functions ] | ||
| 114 | |||
| 115 | -- check if all values of a list are the same | ||
| 116 | all_eq :: [Int] -> Bool | ||
| 117 | all_eq (x:[]) = True | ||
| 118 | all_eq (x:y:xs) | ||
| 119 | | x == y = all_eq (y:xs) | ||
| 120 | | otherwise = False | ||
| 121 | |||
| 122 | -- check if a list contains no duplicates | ||
| 123 | --no_dups :: [Int] -> Bool | ||
| 124 | --no_dups [] = True | ||
| 125 | --no_dups (x:xs) | ||
| 126 | -- | x `elem` xs = False | ||
| 127 | -- | otherwise = no_dups xs | ||
| 128 | |||
| 129 | prop_allImplsEq_a :: [Int] -> Bool | ||
| 130 | prop_allImplsEq_a xs = all_eq $ calc_all (nub xs) | ||
| 131 | |||
| 132 | -- keine negativen listenelemented durch vorbedingung entfernt | ||
| 133 | prop_allImplsEq_b :: [Int] -> Property | ||
| 134 | prop_allImplsEq_b xs = all (>=0) xs ==> all_eq $ calc_all (nub xs) | ||
| 135 | |||
