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

Re: [MacPerl] The Powers of Annoy



step 1) People generally are more willing to look at code if it's unobfuscated. (unless of course the question is how to make it more obfuscated). Below is a nice show of what your scrip should look like.
step 1b) that also applys to useful variable names. But that's always personal preferance, and I haven't looked at the code yet.
step 2) my comments to answer your question are below as well delimited by comment marks

$f = "54321";
$fl= length($f);
$e = 2**$fl-1;
$" = ", ";
@o = ($f, "", "");
print "\n\nThe Towers of Annoy\n\nInitial state: @o\n";
$y=0;
$n=0;
### above two lines could be ($y, $n) = (0,0);
until ($n >= $e) {
     chop(@o[$y]);
     $u = $y;
     $y=(($y+1)%3);
### $y = ++$y %3;
### I'd like to do a ++$y%=3; but unfortunately that doesn't work :)
     $o[$y] .= "1";
     $n++;
     print "Move #$n: @o\n";
     unless ($n >= $e) {
          $p = @o[$u];
          $s = length($p);
          $g = substr($p, $s-1, 1);
          $v = (3-($y+$u)); 
### $v = 3 - $y - $u;
          $r = @o[$v];
          $t = length($r);
          $h = substr($r, $t-1, 1);
          if ($h eq "") {
               chop(@o[$u]);
               @o[$v] .= $g;
          } elsif (($g eq "") || ($h lt $g)) {
### } elsif ($g eq '' or $h lt $g) {
### also if they're all numerical why not use numerical comparisons?
               chop(@o[$v]);
               @o[$u] .= $h;
          } else {
               chop(@o[$u]);
               @o[$v] .= $g;
          }
          $n++;
          print "Move #$n: @o\n";
     }
}
__END__

le meas,
--Nick

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org