Exercise 1 and 2: formableBy and wordsFrom

This commit is contained in:
mandlm 2016-10-15 12:25:03 +02:00
parent 8eb0326df5
commit fe0781b614
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,22 @@
module Scrabble where
import Words
import Data.List
type Hand = [Char]
formableBy :: String -> Hand -> Bool
formableBy [] _ = True
formableBy (x:xs) hand = let remainingHand = delete x hand in
elem x hand && formableBy xs remainingHand
wordsFrom :: Hand -> [String]
wordsFrom hand = wordsFromList hand allWords
wordsFromList :: Hand -> [String] -> [String]
wordsFromList hand [] = []
wordsFromList hand (x:[])
| formableBy x hand = [x]
| otherwise = []
wordsFromList hand (x:xs) = wordsFromList hand [x] ++ wordsFromList hand xs

File diff suppressed because one or more lines are too long