[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] Recursion, anyone?



In a recent article in The Scientist, a commentator states "There is no
counting of www.--ics.com sites to be found on the web."  Well, of course
there IS counting them, using basic sockets, if one can only come up with
all the possible name combinations.

To that end, here is my little attempt at recursion (I'm sure there is a
whole bunch of material out there on this, but this is my own attempt,
because it was fun, as in FWP).  It generates all possible
letter/number/dash combinations of a specified length (actually, by adding
the space in the array of possible elements, and s/\s//g, one could find all
possible combination of any length up to the specified length).  You specify
the length at the command line.

Anyone care to improve on my first attempt?  If someone reduces this to a
one-liner, I promise never to post again!  

Eric
-------8<---------------------------------------------

#!/usr/bin/perl

$max = $ARGV[0];
$continue = 1;

@el=(A..Z,a..z,0..9);
push @el, "-"; #can't add this to the list above, for some reason

for(0..$max) {push @i, 0};

while ($continue == 1)
{
  $word = "";
  for ($letter=0; $letter<@i;$letter++)
  {
    $word .= $el[$i[$letter]];  
  }
  
  print "$word\n";
  
  for($inc=0;$inc<@i;$inc++)
  {
    if($flag==0)
    {
      $i[$inc]++;
      if ($i[$inc] > @el)
      {
        $i[$inc] = 0;
      } else
      {
        $flag = 1;
      }
    }
  }
  if ($flag == 0) {$continue = 0};
  $flag = 0;
}

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe