summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AufgabeFFP8.hs43
1 files changed, 23 insertions, 20 deletions
diff --git a/AufgabeFFP8.hs b/AufgabeFFP8.hs
index 89c3a66..d328ae8 100644
--- a/AufgabeFFP8.hs
+++ b/AufgabeFFP8.hs
@@ -4,6 +4,7 @@ where
4import Data.Array 4import Data.Array
5import Data.List hiding ((\\)) 5import Data.List hiding ((\\))
6import Test.QuickCheck 6import Test.QuickCheck
7import Debug.Trace
7 8
8type Nat = Int 9type Nat = Int
9 10
@@ -29,31 +30,31 @@ checklist xs = accumArray (||) False (0,n)
29 where n = length xs 30 where n = length xs
30 31
31-- minfree countlist 32-- minfree countlist
32 33
33minfree_col :: [Int] -> Int 34minfree_col :: [Int] -> Int
34minfree_col = search0 . assocs . countlist 35minfree_col = search_countlist . countlist
35 36
36countlist :: [Int] -> Array Int Int 37countlist :: [Int] -> Array Int Int
37countlist xs = accumArray (+) 0 (0,n) (zip xs (repeat 1)) 38countlist xs = accumArray (+) 0 (0, n) (zip xs (repeat 1))
38 where n = length xs 39 where n = safe_maximum xs
39 40
40sort :: [Int] -> [Int] 41safe_maximum :: [Int] -> Int
41sort xs = concat [replicate k x | (x,k) <- assocs $ countlist xs] 42safe_maximum [] = 0
43safe_maximum xs = maximum xs
42 44
43search0 :: [(Int, Int)] -> Int 45search_countlist :: Array Int Int -> Int
44search0 [] = -1 46search_countlist = length . takeWhile (/= 0) . elems
45search0((i,0):_) = i
46search0 (x:xs) = search0 xs
47 47
48-- minfree basic daq 48-- minfree basic daq
49 49
50minfree_b :: [Int] -> Int 50minfree_b :: [Int] -> Int
51minfree_b xs = if (null ([0..b-1] \\ us)) 51minfree_b xs = if (null ([0..b-1] \\ us))
52 then (head ([b..] \\ vs)) 52 then (head ([b..] \\ vs))
53 else (head ([0..] \\ us)) 53 else (head ([0..] \\ us))
54 where 54 where
55 b = 1 + (length xs) `div` 2 55 (us, vs) = partition (<b) xs
56 (us, vs) = partition (<b) xs 56 b = 1 + (length xs) `div` 2
57
57 58
58-- minfree refined daq 59-- minfree refined daq
59 60
@@ -64,7 +65,7 @@ minfrom_r :: Nat -> [Nat] -> Nat
64minfrom_r a xs 65minfrom_r a xs
65 | null xs = a 66 | null xs = a
66 | length us == b-a = minfrom_r b vs 67 | length us == b-a = minfrom_r b vs
67 | otherwise = minfrom_r b us 68 | otherwise = minfrom_r a us
68 where 69 where
69 b = a + 1 + (length xs) `div` 2 70 b = a + 1 + (length xs) `div` 2
70 (us, vs) = partition (<b) xs 71 (us, vs) = partition (<b) xs
@@ -111,8 +112,10 @@ b_combine b _ (us:vs:[]) = if (null ([0..b-1] \\ us))
111 else ([0..] \\ us) 112 else ([0..] \\ us)
112 113
113minfree_bhof :: [Int] -> Int 114minfree_bhof :: [Int] -> Int
115minfree_bhof [] = 0
114minfree_bhof xs = head $ divideAndConquer (b_indiv (length xs)) b_solve (b_divide b) (b_combine b) xs 116minfree_bhof xs = head $ divideAndConquer (b_indiv (length xs)) b_solve (b_divide b) (b_combine b) xs
115 where b = 1+(length xs) `div` 2 117 where b = 1+(length xs) `div` 2
118
116 119
117-- minfree refined daq higher order 120-- minfree refined daq higher order
118 121
@@ -165,11 +168,11 @@ minfree_ohof xs = divideAndConquer o_indiv o_solve o_divide o_combine (0, length
165 168
166functions = [ minfree_bv, minfree_chl, minfree_col, 169functions = [ minfree_bv, minfree_chl, minfree_col,
167 minfree_b, minfree_r, minfree_o, 170 minfree_b, minfree_r, minfree_o,
168 minfree_bhof] 171 minfree_bhof, minfree_rhof, minfree_ohof]
169 172
170-- calc values of all function 173-- calc values of all function
171calc_all :: [Int] -> [Int] 174calc_all :: [Int] -> [Int]
172calc_all xs = [ f xs | f <- functions ] 175calc_all xs = [f xs | f <- functions ]
173 176
174-- check if all values of a list are the same 177-- check if all values of a list are the same
175all_eq :: [Int] -> Bool 178all_eq :: [Int] -> Bool