From 2eb3ebc3247656c246258fd6a078fa5801ff80f3 Mon Sep 17 00:00:00 2001 From: Matthias Wisniowski Date: Sun, 6 May 2012 22:24:13 +0200 Subject: Aufgabe 5, 4. Almost done, except testing errors --- AufgabeFFP5.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'AufgabeFFP5.hs') diff --git a/AufgabeFFP5.hs b/AufgabeFFP5.hs index c528be4..3fb926c 100644 --- a/AufgabeFFP5.hs +++ b/AufgabeFFP5.hs @@ -97,3 +97,22 @@ divideAndConquer indiv solve divide combine initPb = dAC initPb -- 4. ------------------------------------------------------------------------------- +miIndiv :: [a] -> Bool +miIndiv a = length a <= 1 + +miSolve :: (Ix a, Show a) => (b -> Bool) -> [(a,b)] -> [(a,b)] +miSolve wf [(a,b)] + | wf b = [(a,b)] + | otherwise = [] + +miDivide :: [a] -> [[a]] +miDivide (x:xs) = [[x], xs] + +miCombine :: [a] -> [[a]] -> [a] +miCombine _ [] = error "No matching index" +miCombine a (x:xs) + | null x = miCombine a xs + | otherwise = [head x] + +minIndex :: (Ix a, Show a) => Array a b -> (b -> Bool) -> a +minIndex a wf = fst $ head $ divideAndConquer miIndiv (miSolve wf) miDivide miCombine $ assocs a \ No newline at end of file -- cgit v1.2.3