Commit 3ebcbb8c authored by Georgi Angelov's avatar Georgi Angelov
Browse files

Refactored Utils.hs

parent b9d6d33a
......@@ -3,25 +3,20 @@ module Utils where
import Solver
-- Receives a list of possible answers to a clue and returns a list of all valid answers
solveAnswers clue wordLength answers
= solveEach clue wordLength (wordsWhen (==',') answers)
where
solveEach _ _ [] = []
solveEach clue wordLength (a:as)
| null (solveWithAnswerReturn (clue, wordLength) a)
= solveEach clue wordLength as
| otherwise
= head (solveWithAnswerReturn (clue, wordLength) a) : solveEach clue wordLength as
solveAnswers = genericSolveAnswers solveWithAnswerReturn
-- Receives a list of possible answers to a clue and returns a list of all valid answers with explanations
solveAnswersAndExplain = genericSolveAnswers solveWithAnswerReturnExpl
solveAnswersAndExplain clue wordLength answers
genericSolveAnswers solveVariation clue wordLength answers
= solveEach clue wordLength (wordsWhen (==',') answers)
where
solveEach _ _ [] = []
solveEach clue wordLength (a:as)
| null (solveWithAnswerReturnExpl (clue, wordLength) a)
| null (solveVariation (clue, wordLength) a)
= solveEach clue wordLength as
| otherwise
= head (solveWithAnswerReturnExpl (clue, wordLength) a) : solveEach clue wordLength as
= head (solveVariation (clue, wordLength) a) : solveEach clue wordLength as
-- Helper function to split string by character into a list of strings
wordsWhen :: (Char -> Bool) -> String -> [String]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment