From 17e9463688dce3f5ee4e192ef3574925f13f8c36 Mon Sep 17 00:00:00 2001 From: Matthias Wisniowski Date: Wed, 30 May 2012 03:39:03 +0200 Subject: =?UTF-8?q?Dirty=20fix=20f=C3=BCr=208.1,=20aber=20ich=20hab=20kein?= =?UTF-8?q?e=20lust=20mehr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AufgabeFFP8.hs | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'AufgabeFFP8.hs') diff --git a/AufgabeFFP8.hs b/AufgabeFFP8.hs index 89c3a66..d328ae8 100644 --- a/AufgabeFFP8.hs +++ b/AufgabeFFP8.hs @@ -4,6 +4,7 @@ where import Data.Array import Data.List hiding ((\\)) import Test.QuickCheck +import Debug.Trace type Nat = Int @@ -29,31 +30,31 @@ checklist xs = accumArray (||) False (0,n) where n = length xs -- minfree countlist - + minfree_col :: [Int] -> Int -minfree_col = search0 . assocs . countlist +minfree_col = search_countlist . countlist countlist :: [Int] -> Array Int Int -countlist xs = accumArray (+) 0 (0,n) (zip xs (repeat 1)) - where n = length xs - -sort :: [Int] -> [Int] -sort xs = concat [replicate k x | (x,k) <- assocs $ countlist xs] +countlist xs = accumArray (+) 0 (0, n) (zip xs (repeat 1)) + where n = safe_maximum xs + +safe_maximum :: [Int] -> Int +safe_maximum [] = 0 +safe_maximum xs = maximum xs -search0 :: [(Int, Int)] -> Int -search0 [] = -1 -search0((i,0):_) = i -search0 (x:xs) = search0 xs +search_countlist :: Array Int Int -> Int +search_countlist = length . takeWhile (/= 0) . elems -- minfree basic daq minfree_b :: [Int] -> Int -minfree_b xs = if (null ([0..b-1] \\ us)) - then (head ([b..] \\ vs)) - else (head ([0..] \\ us)) - where - b = 1 + (length xs) `div` 2 - (us, vs) = partition ( [Nat] -> Nat minfrom_r a xs | null xs = a | length us == b-a = minfrom_r b vs - | otherwise = minfrom_r b us + | otherwise = minfrom_r a us where b = a + 1 + (length xs) `div` 2 (us, vs) = partition ( Int +minfree_bhof [] = 0 minfree_bhof xs = head $ divideAndConquer (b_indiv (length xs)) b_solve (b_divide b) (b_combine b) xs where b = 1+(length xs) `div` 2 + -- minfree refined daq higher order @@ -165,11 +168,11 @@ minfree_ohof xs = divideAndConquer o_indiv o_solve o_divide o_combine (0, length functions = [ minfree_bv, minfree_chl, minfree_col, minfree_b, minfree_r, minfree_o, - minfree_bhof] + minfree_bhof, minfree_rhof, minfree_ohof] -- calc values of all function calc_all :: [Int] -> [Int] -calc_all xs = [ f xs | f <- functions ] +calc_all xs = [f xs | f <- functions ] -- check if all values of a list are the same all_eq :: [Int] -> Bool -- cgit v1.2.3