summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortotycro <totycro@unknown-horizons.org>2012-05-29 20:53:29 +0200
committertotycro <totycro@unknown-horizons.org>2012-05-29 20:53:29 +0200
commitb9056493bf23c24a60ce0d259aa648033233e746 (patch)
treecdde0befd88dcabfd5e705edf75e4d030bf7afcb
parent2993b0e41d9647c4e13a414c6dbb766aea11d009 (diff)
downloadffp-b9056493bf23c24a60ce0d259aa648033233e746.tar.gz
ffp-b9056493bf23c24a60ce0d259aa648033233e746.tar.bz2
ffp-b9056493bf23c24a60ce0d259aa648033233e746.zip
checklist & countlist
-rw-r--r--AufgabeFFP8.hs46
1 files changed, 36 insertions, 10 deletions
diff --git a/AufgabeFFP8.hs b/AufgabeFFP8.hs
index c2e3583..298898b 100644
--- a/AufgabeFFP8.hs
+++ b/AufgabeFFP8.hs
@@ -2,7 +2,8 @@ module AufgabeFFP8
2where 2where
3 3
4import Data.Char 4import Data.Char
5import Data.List hiding ((\\), insert, delete) 5import Data.Array
6import Data.List hiding ((\\), insert, delete, sort)
6import Test.QuickCheck 7import Test.QuickCheck
7 8
8type Nat = [Int] 9type Nat = [Int]
@@ -14,27 +15,52 @@ minfree_bv :: [Int] -> Int
14minfree_bv xs = head ([0..] \\ xs) 15minfree_bv xs = head ([0..] \\ xs)
15 16
16-- checklist 17-- checklist
17--minfree_chl :: [Int] -> Int 18minfree_chl :: [Int] -> Int
19minfree_chl = search . checklist
20
21search :: Array Int Bool -> Int
22search = length . takeWhile id . elems
23
24checklist :: [Int] -> Array Int Bool
25checklist xs = accumArray (||) False (0, n)
26 (zip (filter (<=n) xs) (repeat True))
27 where n = length xs
18 28
19-- countlist 29-- countlist
20--minfree_col :: [Int] -> Int 30minfree_col :: [Int] -> Int
31minfree_col = search_countlist . countlist
32
33countlist :: [Int] -> Array Int Int
34countlist xs = accumArray (+) 0 (0, n) (zip xs (repeat 1))
35 where n = safe_maximum xs
36
37safe_maximum :: [Int] -> Int
38safe_maximum [] = 0
39safe_maximum xs = maximum xs
40
41-- unused
42sort :: [Int] -> [Int]
43sort xs = concat [replicate k x | (x, k) <- assocs ( countlist xs ) ]
44
45search_countlist :: Array Int Int -> Int
46search_countlist = length . takeWhile (/= 0) . elems
21 47
22-- basic divice-and-conquer 48-- basic divide-and-conquer
23--minfree_b :: [Int] -> Int 49minfree_b :: [Int] -> Int
24 50
25-- refined divice-and-conquer 51-- refined divide-and-conquer
26--minfree_r :: [Int] -> Int 52--minfree_r :: [Int] -> Int
27 53
28-- optimised divice-and-conquer 54-- optimised divide-and-conquer
29--minfree_o :: [Int] -> Int 55--minfree_o :: [Int] -> Int
30-- 56--
31-- basic divice-and-conquer mittels higher order function 57-- basic divide-and-conquer mittels higher order function
32--minfree_bhof :: [Int] -> Int 58--minfree_bhof :: [Int] -> Int
33 59
34-- refined divice-and-conquer mittels higher order function 60-- refined divide-and-conquer mittels higher order function
35--minfree_rhof :: [Int] -> Int 61--minfree_rhof :: [Int] -> Int
36 62
37-- optimised divice-and-conquer mittels higher order function 63-- optimised divide-and-conquer mittels higher order function
38--minfree_ohof :: [Int] -> Int 64--minfree_ohof :: [Int] -> Int
39 65
40 66