Anagrams/Deranged anagrams: Difference between revisions

m
→‎{{header|Perl}}: future-proof for 5.36, use new bitwise string operators
(→‎{{header|Haskell}}: Added a variant)
m (→‎{{header|Perl}}: future-proof for 5.36, use new bitwise string operators)
Line 3,848:
 
=={{header|Perl}}==
===String operations===
<syntaxhighlight lang="perl">sub deranged { # only anagrams ever get here
<syntaxhighlight lang="perl">#!/usr/bin/perluse strict;
use warnings;
 
<syntaxhighlight lang="perl">sub deranged { # only anagrams ever get here
my @a = split('', shift); # split word into letters
my @b = split('', shift);
Line 3,882 ⟶ 3,886:
keys %letter_list )
{
# if we find a pair, they are the longestedlongest due to the sort before
last if find_deranged(@{ $letter_list{$_} });
}</syntaxhighlight>
{{out}}
<pre>length 10: excitation => intoxicate</pre>
<pre>
===Bitwise operations===
length 10: excitation => intoxicate
<syntaxhighlight lang="perl">use strict;
</pre>
===Alternate===
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Anagrams/Deranged_anagrams
use warnings;
use feature 'bitwise';
 
local (@ARGV, $/) = 'unixdict.txt';
Line 3,901 ⟶ 3,902:
{
my $key = join '', sort +split //, $word;
($_ ^. $word) =~ /\0/ or exit !print "$_ $word\n" for @{ $anagrams{$key} };
push @{ $anagrams{$key} }, $word;
}</syntaxhighlight>
{{out}}
<pre>excitation intoxicate</pre>
<pre>
excitation intoxicate
</pre>
 
=={{header|Phix}}==
2,392

edits