Skip to content

Commit

Permalink
Implement matches
Browse files Browse the repository at this point in the history
  • Loading branch information
MMZK1526 committed Aug 31, 2024
1 parent 154727b commit 14157dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc-jan-haskell.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ library
build-depends:
base >= 4.17.2 && < 4.18,
containers >= 0.6.7 && < 0.7,
filepath,
mtl >= 2.2.2 && < 2.3,
text >= 2.0.2 && < 2.1,
transformers >= 0.5.6 && < 0.6,
Expand Down
12 changes: 7 additions & 5 deletions src/Year2023/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ matches clue (Charade _ t1 t2) = or [ matches c1 t1 && matches c2 t2

evaluate :: Parse -> Int -> [String]
evaluate (defs, _, tree) size
= undefined
= concatMap (filter isMatch . synonyms) defs
where
isMatch syn = length syn >= size && matches syn tree

------------------------------------------------------
-- Part III
Expand All @@ -68,9 +70,9 @@ parseWordplay ws
parseReversal ws,
parseInsertion ws,
parseCharade ws]

parseSynonym :: [String] -> [ParseTree]
parseSynonym
parseSynonym
= const []

parseAnagram :: [String] -> [ParseTree]
Expand All @@ -86,7 +88,7 @@ parseInsertion
= const []

parseCharade :: [String] -> [ParseTree]
parseCharade
parseCharade
= const []

-- Given...
Expand All @@ -99,7 +101,7 @@ parseClueText
= undefined

solve :: Clue -> [Solution]
solve
solve
= undefined


Expand Down
14 changes: 12 additions & 2 deletions src/Year2023/WordData.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- > This is needed to access __FILE__, the macro for the path of the current
-- > source file. See the comment on "thesaurus".
{-# LANGUAGE CPP #-}

module Year2023.WordData where

import System.IO
Expand All @@ -6,6 +10,8 @@ import System.IO.Unsafe
import qualified Data.Text as Text
import qualified Data.Text.IO as TextIO
import qualified Data.Map as Map

import System.FilePath

Check failure on line 14 in src/Year2023/WordData.hs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 9.4.7)

Could not load module ‘System.FilePath’

synonyms :: String -> [String]
synonyms s
Expand All @@ -14,11 +20,15 @@ synonyms s
lookUp x t
= fromMaybe [] (Map.lookup x t)

-- > The original skeleton code simply reads from the path "thesaurus.txt".
-- > However, this no longer works when I incorporate all previous tests into
-- > this single repo as the directory layout has been altered. Therefore I
-- > use the macro __FILE__ to always locate the thesaurus file relatively.
thesaurus :: Map.Map String [String]
thesaurus
= unsafePerformIO $
= unsafePerformIO $
do
ls <- fmap Text.lines (TextIO.readFile "thesaurus.txt")
ls <- fmap Text.lines (TextIO.readFile $ replaceFileName __FILE__ "thesaurus.txt")
return (Map.fromList (fmap (readSyns . Text.unpack) ls))

readWord :: String -> String
Expand Down

0 comments on commit 14157dd

Please sign in to comment.