Anagrams/Deranged anagrams: Difference between revisions

Content added Content deleted
(Added Arturo implementation)
Line 3,981: Line 3,981:
excitation intoxicate
excitation intoxicate
</pre>
</pre>

=={{header|Picat}}==
<lang Picat>
go =>
M = [W:W in read_file_lines("unixdict.txt")].group(sort),
Deranged = [Value : _Key=Value in M, Value.length > 1, allderanged(Value)],
MaxLen = max([V[1].length : V in Deranged]),
println([V : V in Deranged, V[1].length==MaxLen]),
nl.

% A and B are deranged: i.e. there is no
% position with the same character.
deranged(A,B) =>
foreach(I in 1..A.length)
A[I] != B[I]
end.

% All words in list Value are deranged anagrams of each other.
allderanged(Value) =>
IsDeranged = 1,
foreach(V1 in Value, V2 in Value, V1 @< V2, IsDeranged = 1)
if not deranged(V1,V2) then
IsDeranged := 0
end
end,
IsDeranged == 1.


% Groups the element in List according to the function F
group(List, F) = P, list(List) =>
P = new_map(),
foreach(E in List)
V = apply(F,E),
P.put(V, P.get(V,[]) ++ [E])
end.</lang>

Output:
<pre>[[excitation,intoxicate]]</pre>



=={{header|PicoLisp}}==
=={{header|PicoLisp}}==