Exercise 6: bestWords

master
mandlm 2016-10-16 13:17:59 +02:00
parent 9e4ebcd26d
commit a6012c32a1
1 changed files with 20 additions and 2 deletions

View File

@ -48,7 +48,25 @@ wordsFromListFittingTemplate template hand (x:xs)
wordsFittingTemplate :: Template -> Hand -> [String]
wordsFittingTemplate template hand = wordsFromListFittingTemplate template hand allWords
scrabbleValueWord :: String -> Int
scrabbleValueWord [] = 0
scrabbleValueWord (x:xs) = scrabbleValue x + scrabbleValueWord xs
bestScrabbleWordValueAcc :: [String] -> Int -> Int
bestScrabbleWordValueAcc [] acc = acc
bestScrabbleWordValueAcc (x:xs) acc = let currentWordValue = scrabbleValueWord x in
let bestValue = max currentWordValue acc in
bestScrabbleWordValueAcc xs bestValue
bestScrabbleWordValue :: [String] -> Int
bestScrabbleWordValue words = bestScrabbleWordValueAcc words 0
bestWords :: [String] -> [String]
bestWords [] = []
bestWords (x:xs)
| scrabbleValueWord(x) == maxWordValue = x : bestWords xs
| otherwise = bestWords xs
where
maxWordValue = bestScrabbleWordValue (x:xs)