Name: Anonymous 2008-06-11 18:30
FUCK YOU PROG. YOU DESTROYED MY LIFE. EVERY MINUTE I REFRESH PROG AND SEE ONLY SPAM, YET I KEEP COMING BACK. I CANT STOP LURKING. LET ME GO YOU BASTARDS.
`D\D\.-
(0.0 \
\`-'J ) ---Java
- -\
(|| ( J_
c_|-c_J--,)
.
. ,
/ ). ---Java
.(_/ )
(___/_).
-- Ananagrams
--
-- http://www.streamtech.nl/problemset/156.html
--
-- Write a program that will read in the dictionary of a restricted
-- domain and determine the relative ananagrams. Note that single
-- letter words are, ipso facto, relative ananagrams since they cannot
-- be ``rearranged'' at all. The dictionary will contain no more than
-- 1000 words.
--
-- run ghci, and execute:
-- > :l Ananagrams.hs
-- Ananagrams*> showAnsOfFile "words.txt"
--
-- Takes about 1 second to do 1881 words, separated into 882 lines
-- of a file, from http://www.buber.net/Basque/Euskara/hitz.html
module Ananagram where
import Data.List
import Data.Char
import Data.Function
import Data.Map hiding (map)
ananagrams :: [String] -> [String]
ananagrams = elems . mapMaybe oneItem . foldr insert empty where
insert w = insertWith ((:) . head) (canonize w) [w]
canonize = sort . map toLower
oneItem [a] = Just a
oneItem _ = Nothing
-- are two strings an anagram?
isAnagram :: String -> String -> Bool
isAnagram = (==) `on` sort . map toLower
readWords :: String -> [String]
readWords = words . unlines . takeWhile (/="#") . lines
ananagramsOfFile :: FilePath -> IO [String]
ananagramsOfFile p = readFile p >>= return . ananagrams . readWords
showAnsOfFile :: FilePath -> IO ()
showAnsOfFile p = ananagramsOfFile p >>= putStrLn . unlines
-- Ananagrams
--
-- http://www.streamtech.nl/problemset/156.html
--
-- Write a program that will read in the dictionary of a restricted
-- domain and determine the relative ananagrams. Note that single
-- letter words are, ipso facto, relative ananagrams since they cannot
-- be ``rearranged'' at all. The dictionary will contain no more than
-- 1000 words.