From 46e188c83e0ca7456420f4010b5b7b0422dc6acd Mon Sep 17 00:00:00 2001 From: totycro Date: Tue, 29 May 2012 22:17:38 +0200 Subject: first minfree hof (basic) --- AufgabeFFP8.hs | 27 +++++++++++++++++++++++++-- 1 file 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 -- basic divide-and-conquer mittels higher order function ---minfree_bhof :: [Int] -> Int +minfree_bhof :: [Int] -> Int +minfree_bhof xs = divideAndConquer b_indiv b_solve b_divide b_combine (length xs, xs) + +b_indiv :: (Int, [Int]) -> Bool +b_indiv (0, _) = True -- empty list +b_indiv (n, xs) = n /= length xs -- only divide on first call + +b_solve :: (Int, [Int]) -> Int +b_solve (n, xs) = head $ [n..] \\ xs + +b_divide :: (Int, [Int]) -> [ (Int, [Int]) ] +b_divide (n, xs) = [(0, us), (b, vs)] + where + b = 1 + (length xs) `div` 2 + (us, vs) = partition ( [Int] -> Int +b_combine xs sols = head sols + -- refined divide-and-conquer mittels higher order function --minfree_rhof :: [Int] -> Int +--minfree_rhof = divideAndConquer r_indiv r_solve r_divide r_combine +-- +--r_indiv :: (Int, [Int]) -> Bool +--r_indiv (a, xs) -- optimised divide-and-conquer mittels higher order function --minfree_ohof :: [Int] -> Int @@ -106,7 +128,8 @@ divideAndConquer indiv solve divide combine initPb = dAC initPb -- QuickCheck part functions = [ minfree_bv, minfree_chl, minfree_col, - minfree_b, minfree_r, minfree_o ] + minfree_b, minfree_r, minfree_o, + minfree_bhof] -- calc values of all function calc_all :: [Int] -> [Int] -- cgit v1.2.3