Help Understanding Script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samthemist
    New Member
    • Jul 2007
    • 34

    Help Understanding Script?

    I want to understand how exactly this script works. Basically, it returns every combination that is possible using '.' - for example:

    sam
    s.am
    sa.m
    s.a.m

    Can you explain what exactly it is going through on each step? I understand some of it, but not others - like $combinations = 1 << ($strlength - 1);

    Code:
    sub isBitSet { if ($_[0] & (1 << ($_[1] - 1))) { return 1; } else { return 0; }}
    
    sub possibilize {
      $strlength = length($_[0]);
      if ($strlength > 20) { return 0; }
      $combinations = 1 << ($strlength - 1);
      $strloc = 0; $str = "";
      for ($x = 0; $x < $combinations; $x++) {
        $strloc = 1; $str = $_[0];
        for ($y = 1; $y < $strlength; $y++) {
          $str = substr($str, 0, $strloc);
          if (isBitSet($x, $y)) { $str.= "."; $strloc++; } 
          $str.= substr($_[0], $y); $strloc++;
        } $out.= $str.
      } return $out;
    }
  • samthemist
    New Member
    • Jul 2007
    • 34

    #2
    Can anyone explain?
    ...

    Comment

    Working...