summaryrefslogtreecommitdiffstats
path: root/AufgabeFFP8.hs
diff options
context:
space:
mode:
authortotycro <totycro@unknown-horizons.org>2012-05-29 22:17:38 +0200
committertotycro <totycro@unknown-horizons.org>2012-05-29 22:17:38 +0200
commit46e188c83e0ca7456420f4010b5b7b0422dc6acd (patch)
treeaab4bf075f623dc7edba5761c44d3f5704f4b0ac /AufgabeFFP8.hs
parent5bb2754dfdd3c5a1d795b286ed5d762375e10752 (diff)
downloadffp-46e188c83e0ca7456420f4010b5b7b0422dc6acd.tar.gz
ffp-46e188c83e0ca7456420f4010b5b7b0422dc6acd.tar.bz2
ffp-46e188c83e0ca7456420f4010b5b7b0422dc6acd.zip
first minfree hof (basic)
Diffstat (limited to 'AufgabeFFP8.hs')
-rw-r--r--AufgabeFFP8.hs27
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 96minfree_bhof :: [Int] -> Int
97minfree_bhof xs = divideAndConquer b_indiv b_solve b_divide b_combine (length xs, xs)
98
99b_indiv :: (Int, [Int]) -> Bool
100b_indiv (0, _) = True -- empty list
101b_indiv (n, xs) = n /= length xs -- only divide on first call
102
103b_solve :: (Int, [Int]) -> Int
104b_solve (n, xs) = head $ [n..] \\ xs
105
106b_divide :: (Int, [Int]) -> [ (Int, [Int]) ]
107b_divide (n, xs) = [(0, us), (b, vs)]
108 where
109 b = 1 + (length xs) `div` 2
110 (us, vs) = partition (<b) xs
111
112b_combine :: (Int, [Int]) -> [Int] -> Int
113b_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
108functions = [ minfree_bv, minfree_chl, minfree_col, 130functions = [ 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
112calc_all :: [Int] -> [Int] 135calc_all :: [Int] -> [Int]