This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
CIS194/Lecture 02/Scrabble/Scrabble.hs

23 lines
543 B
Haskell

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