Teacup rim text: Difference between revisions
Content deleted Content added
→{{header|Haskell}}: Switched from unix to MIT dictionary, formatted output |
|||
Line 114:
=={{header|Haskell}}==
Circular words of more than 2 characters in a local copy of unixdict.txt
<lang haskell>import
import Control.Applicative (liftA2)
import qualified Data.Set as S
import Data.Ord (comparing)
import Data.Function (on)
main :: IO ()
main =
circularWords :: [String] -> [String]
Line 126 ⟶ 131:
isCircular :: S.Set String -> String -> Bool
isCircular lex w = 2 < length w && all (`S.member` lex) (rotations w)
rotations :: [a] -> [[a]]
rotations = liftA2 fmap rotated (enumFromTo 0 . pred . length)
Line 134 ⟶ 138:
rotated :: [a] -> Int -> [a]
rotated [] _ = []
rotated xs n = zipWith const (drop n (cycle xs)) xs
showGroups :: [String] -> String
showGroups xs =
unlines $
intercalate " -> " . fmap snd <$>
groupBy (on (==) fst) (sortBy (comparing fst) (((,) =<< sort) <$> xs))</lang>
{{Out}}
<pre>aaa
arc -> car -> rca
ate -> eat -> tea
aim -> ima -> mai
asp -> pas -> spa
iii
ips -> psi -> sip
ooo
www
xxx</pre>
=={{header|JavaScript}}==
|