Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Create anagrams simply

by Darkling (Beadle)
on Mar 03, 2002 at 02:53 UTC ( #148927=snippet: print w/replies, xml ) Need Help??
Description: Just a really quick sub for creating anagrams of words.
I made a nice little console game with this.
sub anagram
{
   my $orig=shift;
   $word=join("",sort(split(//,$orig))); #Got to be a better way!
   my $anagram=$word;

   do
   {
      $anagram="";
      for (0..length $word)
      {
         if (rand(1)<0.5) #Tag letter onto end or start?
         {
            $anagram.=substr($word,$_,1);
         }
         else
         {
            $anagram=substr($word,$_,1).$anagram;
         }
      }
   } while ($anagram eq $orig); #Make sure it's not the same.

   return $anagram; #Woo!
}
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://148927]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2023-03-29 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (73 votes). Check out past polls.

    Notices?