Anagrams: Difference between revisions

Content added Content deleted
(added java)
mNo edit summary
Line 1: Line 1:
{{task|Text processing}}
{{task|Text processing}}
Two or more words can be composed of the same characters, but in a different order. Using the word list at http://www.puzzlers.org/pub/wordlists/unixdict.txt, find the sets of words that share the same characters that contain the most words in them.
Two or more words can be composed of the same characters, but in a different order. Using the word list at http://www.puzzlers.org/pub/wordlists/unixdict.txt, find the sets of words that share the same characters that contain the most words in them.

== {{header|Haskell}} ==

<pre>
import Data.List

groupon f x y = (f x) == (f y)

main = do
f <- readFile "./../Puzzels/Rosetta/unixdict.txt"
let words = lines f
wix = groupBy (groupon fst) . sort $ zipWith ((,).sort) words words
mxl = foldl' ((.length).max) 0 wix
print . map (map snd) . filter ((==mxl).length) $ wix

</pre>

== {{header|J}} ==

(#~a:~:{:"1)(]/.~/:~&>)<;.2]1!:1<'unixdict.txt'
+-----+-----+-----+-----+-----+
|abel |able |bale |bela |elba |
+-----+-----+-----+-----+-----+
|alger|glare|lager|large|regal|
+-----+-----+-----+-----+-----+
|angel|angle|galen|glean|lange|
+-----+-----+-----+-----+-----+
|caret|carte|cater|crate|trace|
+-----+-----+-----+-----+-----+
|elan |lane |lean |lena |neal |
+-----+-----+-----+-----+-----+
|evil |levi |live |veil |vile |
+-----+-----+-----+-----+-----+


=={{header|Java}}==
=={{header|Java}}==
Line 39: Line 72:
[abel, able, bale, bela, elba]
[abel, able, bale, bela, elba]
[evil, levi, live, veil, vile]
[evil, levi, live, veil, vile]

== {{header|Haskell}} ==

<pre>
import Data.List

groupon f x y = (f x) == (f y)

main = do
f <- readFile "./../Puzzels/Rosetta/unixdict.txt"
let words = lines f
wix = groupBy (groupon fst) . sort $ zipWith ((,).sort) words words
mxl = foldl' ((.length).max) 0 wix
print . map (map snd) . filter ((==mxl).length) $ wix

</pre>

== {{header|J}} ==

(#~a:~:{:"1)(]/.~/:~&>)<;.2]1!:1<'unixdict.txt'
+-----+-----+-----+-----+-----+
|abel |able |bale |bela |elba |
+-----+-----+-----+-----+-----+
|alger|glare|lager|large|regal|
+-----+-----+-----+-----+-----+
|angel|angle|galen|glean|lange|
+-----+-----+-----+-----+-----+
|caret|carte|cater|crate|trace|
+-----+-----+-----+-----+-----+
|elan |lane |lean |lena |neal |
+-----+-----+-----+-----+-----+
|evil |levi |live |veil |vile |
+-----+-----+-----+-----+-----+


=={{header|Python}}==
=={{header|Python}}==