diff options
Diffstat (limited to 'AufgabeFFP8.hs')
| -rw-r--r-- | AufgabeFFP8.hs | 46 |
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 | |||
| 2 | where | 2 | where |
| 3 | 3 | ||
| 4 | import Data.Char | 4 | import Data.Char |
| 5 | import Data.List hiding ((\\), insert, delete) | 5 | import Data.Array |
| 6 | import Data.List hiding ((\\), insert, delete, sort) | ||
| 6 | import Test.QuickCheck | 7 | import Test.QuickCheck |
| 7 | 8 | ||
| 8 | type Nat = [Int] | 9 | type Nat = [Int] |
| @@ -14,27 +15,52 @@ minfree_bv :: [Int] -> Int | |||
| 14 | minfree_bv xs = head ([0..] \\ xs) | 15 | minfree_bv xs = head ([0..] \\ xs) |
| 15 | 16 | ||
| 16 | -- checklist | 17 | -- checklist |
| 17 | --minfree_chl :: [Int] -> Int | 18 | minfree_chl :: [Int] -> Int |
| 19 | minfree_chl = search . checklist | ||
| 20 | |||
| 21 | search :: Array Int Bool -> Int | ||
| 22 | search = length . takeWhile id . elems | ||
| 23 | |||
| 24 | checklist :: [Int] -> Array Int Bool | ||
| 25 | checklist 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 | 30 | minfree_col :: [Int] -> Int |
| 31 | minfree_col = search_countlist . countlist | ||
| 32 | |||
| 33 | countlist :: [Int] -> Array Int Int | ||
| 34 | countlist xs = accumArray (+) 0 (0, n) (zip xs (repeat 1)) | ||
| 35 | where n = safe_maximum xs | ||
| 36 | |||
| 37 | safe_maximum :: [Int] -> Int | ||
| 38 | safe_maximum [] = 0 | ||
| 39 | safe_maximum xs = maximum xs | ||
| 40 | |||
| 41 | -- unused | ||
| 42 | sort :: [Int] -> [Int] | ||
| 43 | sort xs = concat [replicate k x | (x, k) <- assocs ( countlist xs ) ] | ||
| 44 | |||
| 45 | search_countlist :: Array Int Int -> Int | ||
| 46 | search_countlist = length . takeWhile (/= 0) . elems | ||
| 21 | 47 | ||
| 22 | -- basic divice-and-conquer | 48 | -- basic divide-and-conquer |
| 23 | --minfree_b :: [Int] -> Int | 49 | minfree_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 | ||
