diff options
| author | totycro <totycro@unknown-horizons.org> | 2012-05-29 22:17:38 +0200 |
|---|---|---|
| committer | totycro <totycro@unknown-horizons.org> | 2012-05-29 22:17:38 +0200 |
| commit | 46e188c83e0ca7456420f4010b5b7b0422dc6acd (patch) | |
| tree | aab4bf075f623dc7edba5761c44d3f5704f4b0ac | |
| parent | 5bb2754dfdd3c5a1d795b286ed5d762375e10752 (diff) | |
| download | ffp-46e188c83e0ca7456420f4010b5b7b0422dc6acd.tar.gz ffp-46e188c83e0ca7456420f4010b5b7b0422dc6acd.tar.bz2 ffp-46e188c83e0ca7456420f4010b5b7b0422dc6acd.zip | |
first minfree hof (basic)
| -rw-r--r-- | AufgabeFFP8.hs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/AufgabeFFP8.hs b/AufgabeFFP8.hs index f6d9bfd..9d244e6 100644 --- a/AufgabeFFP8.hs +++ b/AufgabeFFP8.hs | |||
| @@ -93,10 +93,32 @@ divideAndConquer indiv solve divide combine initPb = dAC initPb | |||
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | -- basic divide-and-conquer mittels higher order function | 95 | -- basic divide-and-conquer mittels higher order function |
| 96 | --minfree_bhof :: [Int] -> Int | 96 | minfree_bhof :: [Int] -> Int |
| 97 | minfree_bhof xs = divideAndConquer b_indiv b_solve b_divide b_combine (length xs, xs) | ||
| 98 | |||
| 99 | b_indiv :: (Int, [Int]) -> Bool | ||
| 100 | b_indiv (0, _) = True -- empty list | ||
| 101 | b_indiv (n, xs) = n /= length xs -- only divide on first call | ||
| 102 | |||
| 103 | b_solve :: (Int, [Int]) -> Int | ||
| 104 | b_solve (n, xs) = head $ [n..] \\ xs | ||
| 105 | |||
| 106 | b_divide :: (Int, [Int]) -> [ (Int, [Int]) ] | ||
| 107 | b_divide (n, xs) = [(0, us), (b, vs)] | ||
| 108 | where | ||
| 109 | b = 1 + (length xs) `div` 2 | ||
| 110 | (us, vs) = partition (<b) xs | ||
| 111 | |||
| 112 | b_combine :: (Int, [Int]) -> [Int] -> Int | ||
| 113 | b_combine xs sols = head sols | ||
| 114 | |||
| 97 | 115 | ||
| 98 | -- refined divide-and-conquer mittels higher order function | 116 | -- refined divide-and-conquer mittels higher order function |
| 99 | --minfree_rhof :: [Int] -> Int | 117 | --minfree_rhof :: [Int] -> Int |
| 118 | --minfree_rhof = divideAndConquer r_indiv r_solve r_divide r_combine | ||
| 119 | -- | ||
| 120 | --r_indiv :: (Int, [Int]) -> Bool | ||
| 121 | --r_indiv (a, xs) | ||
| 100 | 122 | ||
| 101 | -- optimised divide-and-conquer mittels higher order function | 123 | -- optimised divide-and-conquer mittels higher order function |
| 102 | --minfree_ohof :: [Int] -> Int | 124 | --minfree_ohof :: [Int] -> Int |
| @@ -106,7 +128,8 @@ divideAndConquer indiv solve divide combine initPb = dAC initPb | |||
| 106 | -- QuickCheck part | 128 | -- QuickCheck part |
| 107 | 129 | ||
| 108 | functions = [ minfree_bv, minfree_chl, minfree_col, | 130 | functions = [ minfree_bv, minfree_chl, minfree_col, |
| 109 | minfree_b, minfree_r, minfree_o ] | 131 | minfree_b, minfree_r, minfree_o, |
| 132 | minfree_bhof] | ||
| 110 | 133 | ||
| 111 | -- calc values of all function | 134 | -- calc values of all function |
| 112 | calc_all :: [Int] -> [Int] | 135 | calc_all :: [Int] -> [Int] |
