Next Program Repair Shop 174

Try it Both Ways

        @table = ([0,1,2], [3,4,5], [6,7,8],
                  [0,3,6], [1,4,7], [2,5,8],
                  [0,4,8], [2,4,7]);
        for my $win (@table) {
          my (@x, @y);
          for (@$win) {
            push @x, $_ % 3;
            push @y, int($_ / 3);
          }
          if ($board->[$x[0]][$y[0]] eq $board->[$x[1]][$y[1]] 
          &&  $board->[$x[0]][$y[0]] eq $board->[$x[2]][$y[2]]) {
            return $board->[$x[0]][$y[0]];
          }
        }        
        for my $w (@table) {
          if ($board->[$w->[0]] eq $board->[$w->[1]] 
          &&  $board->[$w->[0]] eq $board->[$w->[2]]) {
            return $board->[$w->[0]];
          }
        }        


Next Copyright © 2002 M. J. Dominus