From ef2756b480d56b5b29f34235e13c2028d125b973 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 21 May 2012 03:00:01 +0200 Subject: implement rest of part 2 of ex. 7 --- AufgabeFFP7.hs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/AufgabeFFP7.hs b/AufgabeFFP7.hs index 9337010..8f2a7c8 100644 --- a/AufgabeFFP7.hs +++ b/AufgabeFFP7.hs @@ -1,7 +1,9 @@ module AufgabeFFP7 where -import List hiding ((\\)) +import Data.Char +import Data.List hiding ((\\)) +import Test.QuickCheck type Buffer = (Int, String) @@ -78,18 +80,18 @@ quickSort lst = divideAndConquer indiv solve divide combine lst divide (l:ls) = [[ x | x <- ls, x <= l], [ x | x <- ls, x > l] ] combine (l:_) [l1,l2] = l1 ++ [l] ++ l2 -removeDuplicates :: [Integer] -> [Integer] +removeDuplicates :: [Int] -> [Int] removeDuplicates xs = nub xs -- from slide 245 -ssfn :: [Integer] -> Integer -ssfn = (sap 0) . removeDuplicates . quickSort +ssfn :: [Int] -> Int +ssfn xs = sap 0 (removeDuplicates (quickSort xs)) -sap :: Integer -> [Integer] -> Integer -sap n [] = 0 +sap :: Int -> [Int] -> Int +sap n [] = n sap n (x:xs) | n /= x = n - | otherwise = sap (n+1) xs + | otherwise = sap (n + 1) xs -- from slide 247 (\\) :: Eq a => [a] -> [a] -> [a] @@ -102,7 +104,12 @@ minfree xs = head ([0..] \\ xs) type Nat = [Int] ---TODO prop_ssfn_eq_minfree_a :: Nat -> Bool +prop_ssfn_eq_minfree_a :: Nat -> Bool +prop_ssfn_eq_minfree_a xs = minfree pos == ssfn pos + where + pos = filter (>= 0) xs ---TODO prop_ssfn_eq_minfree_b :: Nat -> Property +prop_ssfn_eq_minfree_b :: Nat -> Property +prop_ssfn_eq_minfree_b xs = filter (< 0) xs == [] + ==> ssfn xs == minfree xs -- cgit v1.2.3