-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Abhijit Sarkar
committed
Jan 3, 2025
1 parent
7c0f2f6
commit c08fcd6
Showing
8 changed files
with
852 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module Anagrams where | ||
|
||
import Core | ||
import qualified Data.Char as Ch | ||
import qualified Data.Function as Fn | ||
import qualified Functor as F | ||
import List (Chars, FilePath, List (..)) | ||
import qualified List as L | ||
|
||
{- | ||
Functions you will need | ||
-- | ||
\* fmap :: (a -> b) -> IO a -> IO b | ||
\* readFile :: FilePath -> IO Str | ||
\* lines :: Str -> [Str] | ||
\* permutations :: [a] -> [[a]] | ||
\* intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] | ||
\* toLower :: Char -> Char | ||
Functions that might help | ||
- | ||
\* on :: (b -> b -> c) -> (a -> b) -> a -> a -> c | ||
-} | ||
|
||
-- Return all anagrams of the given string | ||
-- that appear in the given dictionary file. | ||
anagrams :: Chars -> FilePath -> IO (List Chars) | ||
anagrams s filename = | ||
L.intersectBy equalIgnoringCase (L.permutations s) . L.lines F.<$> L.readFile filename | ||
|
||
-- Compare two strings for equality, ignoring case | ||
equalIgnoringCase :: Chars -> Chars -> Bool | ||
equalIgnoringCase = Fn.on (==) (Ch.toLower F.<$>) |
Oops, something went wrong.