software-engineering-amsterdam / ST2017_WG_14

0 stars 1 forks source link

Week 2: Exercise 4 and 5 #3

Closed BertLisser closed 7 years ago

BertLisser commented 7 years ago

Exercise 4 Very nice original and short solution.

isPermutation :: Eq a => [a] -> [a] -> Bool
isPermutation xs ys | length xs /= length ys = False
| otherwise = null $ (\\) xs ys

I make it little shorter:

isPermutation :: Eq a => [a] -> [a] -> Bool
isPermutation xs ys  =  (length xs == length ys) &&  null $ xs \\ ys

Perfect

Exercise 5 You have chosen the wrong test cases. Counter examples are permutations but not derangements.

Good

vdweegen commented 7 years ago

Exercise 4 changed to:

isPermutation :: Eq a => [a] -> [a] -> Bool
isPermutation xs ys  =  (length xs == length ys) && null (xs \\ ys)

(differs slightly from proposed solution)

vdweegen commented 7 years ago

Added additional properties for Exercise 5