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

[MacPerl] MacPerl Tool Questions



Hello,

I just downloaded the latest version of the MPW Perl Tool (510r2). I did
not find any "Installation" tips.

I unpacked the distribution into MacPerlTool Folder inside of my MPW 
folder. I am running MPW shell 3.2.3 (OK ETO number 22 is on order).

I did not heed the advice in the installer and had to install the folder
twice ;( (I am running on a 7600).

It has been a number of years since I have had to think hard about MPW.

Evidently @INC comes with only ":" which made things a little tricky
getting started. Here is what I had to do to run a perl script.

1) "cd" to the distribution folder and copy the script into the same
   folder.

2) Issue the command: perl -I :lib scriptname, lib is where the perl
   library lives in the distribution.

Question: Do I have to specify the location of the library file for every
          invocation of perl, or is there some Magical value I can
          set during the startup of MPW that perl will query?

Running the eight queens program from MPW gave times like:

perl -I :lib EightQueens2
Exactly 92 found, in4.86666666666667 seconds
start time was: 0.25 Finish time was 5.11666666666667

perl -I :lib EightQueens2
Exactly 92 found, in5.05 seconds
start time was: 0.15 Finish time was 5.2

Running the program from the MacPerl Application gave times like:

Exactly 92 found, in0.783333333333333 seconds
start time was: 0.45 Finish time was 1.23333333333333
Exactly 92 found, in0.833333333333333 seconds
start time was: 0.366666666666667 Finish time was 1.2
Exactly 92 found, in0.883333333333333 seconds
start time was: 0.316666666666667 Finish time was 1.2

Question: Will the times "equalize" when the latest version of MPW arrives?
          (And I can install the PPC version).

Here is the code see N. Wirth Algorithms + DataStructures = Programs
for an explanation.

#!/usr/bin/perl

# Find all solutions to the eight queens problem on
# an eight by eight board.
# Jerry LeVan <levan@eagle.eku.edu>

@a = (1) x 15 ; # 15 diagonals (1 => unoccupied)
@b = (1) x 15 ; # 15 antidiagonals ( 1 => unoccupied )
@c = (1) x  8 ; #  8 rows ( 1 => unoccupied )

# Store solution here
@x = (undef,(0) x 8 ) ; # skip the zeroth slot

$pflag     =  0 ;  # true if printing solutions desired
$solutions =  0 ;  # total number of solutions
$boardsize =  8 ;  # size of board
@rows      =  (1 .. $boardsize) ;

sub try {

  local($i)=@_ ; # try to put a queen in the ith column

  for $j (@rows ) { # slide down column looking for safe spot
    # is it safe ?
    if ( $a[$i-$j+7] && $b[$i+$j-2] && $c[$j-1]) {

      # yes, mark diagonal, antidiagonal and row as occupied
      $a[$i-$j+7] = $b[$i+$j-2] = --$c[$j-1] ;

      # record solution
      $x[$i] = $j;

      # if not in last column try to extend this solution
      if( $i <  $boardsize ){   &try( $i + 1 ); }
      else {
        # we have a solution so display it
        ++$solutions ;  &printsol if $pflag ;
      }
      # take this queen off and try next row in this column
      $a[$i - $j + 7] = $b[$i + $j -2] = ++$c[$j-1];
    }
   }
}

sub printsol {
  print join(' ',@x), "\n" ;
}

$t1 = (times)[0];
&try(1) ;
$t2= (times)[0];
print "Exactly $solutions found, in",$t2-$t1, " seconds\n" ;
print "start time was: ",$t1," Finish time was ",$t2,"\n";


Thanks,

--Jerry LeVan
  levan@eagle.eku.edu