Jump to content

Anagrams: Difference between revisions

m
no edit summary
(added java)
mNo edit summary
Line 1:
{{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.
 
== {{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}}==
Line 39 ⟶ 72:
[abel, able, bale, bela, elba]
[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}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.