From 9e4ebcd26d5ea7138a45cb0764a7cb429b4780f3 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 15 Oct 2016 17:46:05 +0200 Subject: [PATCH] Exercice 4: wordsFittingTemplate --- Lecture 02/Scrabble/Scrabble.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Lecture 02/Scrabble/Scrabble.hs b/Lecture 02/Scrabble/Scrabble.hs index 2e6e1d5..15720ff 100644 --- a/Lecture 02/Scrabble/Scrabble.hs +++ b/Lecture 02/Scrabble/Scrabble.hs @@ -39,4 +39,16 @@ wordFitsTemplate :: Template -> Hand -> String -> Bool wordFitsTemplate template hand word = let matchWord = removeTemplateChars word template in formableBy matchWord hand && wordMatchesTemplate word template +wordsFromListFittingTemplate :: Template -> Hand -> [String] -> [String] +wordsFromListFittingTemplate _ _ [] = [] +wordsFromListFittingTemplate template hand (x:xs) + | wordFitsTemplate template hand x = x : wordsFromListFittingTemplate template hand xs + | otherwise = wordsFromListFittingTemplate template hand xs + +wordsFittingTemplate :: Template -> Hand -> [String] +wordsFittingTemplate template hand = wordsFromListFittingTemplate template hand allWords + + + +