# New Ticket Created by Leopold Toetsch
# Please include the string: [perl #17705]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=17705 >
This patch corrects an old bug (cut&paste typos) in life.p6 and adds
stats of generations/sec to both. Default generation count is adjusted
to give resaonable runtimes too.
Please apply,
thanks,
leo
-- attachment 1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/38997/31673/3f5af0/life_p6.patch
--- parrot/languages/perl6/examples/life-ar.p6 Sun Aug 25 10:29:05 2002
+++ parrot-leo/languages/perl6/examples/life-ar.p6 Mon Sep 30 18:43:48 2002
@@ -14,7 +14,17 @@
# we don't have �is rw� or call string by refs, so
# input / output are int arrays - slooow
#
-sub Generate(@input, @output) {
+sub Print(@world) {
+ my ($i, $j);
+ for 0..15 -> $i {
+ for 0..15 -> $j {
+ print( @world[$i * 16 + $j] ?? '*' :: ' ');
+ }
+ print "\n" ;
+ }
+ print "----------------\n";
+}
+sub Generate(@input) {
my ($cell, $neighbours, $i);
my $len = 256; #@input;
my ($pos, $offset);
@@ -22,7 +32,7 @@
#my str $death = " ** ";
my @death = (0,0,1,1,0,0,0,0,0);
- @output = @input;
+ my @output = @input;
loop ($cell = 0; $cell < $len; $cell++) {
$neighbours = 0;
@@ -42,19 +52,9 @@
@output[$cell] = 1;
}
}
- #return output;
+ return @output;
}
-sub Print(@world) {
- my ($i, $j);
- for 0..15 -> $i {
- for 0..15 -> $j {
- print( @world[$i * 16 + $j] ?? '*' :: ' ');
- }
- print "\n" ;
- }
- print "----------------\n";
-}
#static void Main()
sub main() {
@@ -78,14 +78,15 @@
);
my ($i, $j, @new);
- my $gen = @ARGS[0] || 512;
+ my $gen = @ARGS[0] || 100;
print "Running ", $gen, " generations\n";
Print(@world);
my $ts = time;
loop( $j= 0 ; $j < $gen; $j++) {
- Generate(@world, @new);
- @world = @new;
+ @world = Generate(@world);
}
+ my $te = time();
Print(@world);
+ print "Gens/s ", $gen/($te-$ts), "\n";
}
--- parrot/languages/perl6/examples/life.p6 Sun Aug 25 10:29:05 2002
+++ parrot-leo/languages/perl6/examples/life.p6 Mon Sep 30 18:57:40 2002
@@ -32,9 +32,9 @@
$neighbours++ if(substr($input, ($i - 17) % $len, 1) eq "*");
$neighbours++ if(substr($input, ($i + 17) % $len, 1) eq "*");
$neighbours++ if(substr($input, ($i - 16) % $len, 1) eq "*");
- $neighbours++ if(substr($input, ($i - 16) % $len, 1) eq "*");
+ $neighbours++ if(substr($input, ($i + 16) % $len, 1) eq "*");
+ $neighbours++ if(substr($input, ($i - 15) % $len, 1) eq "*");
$neighbours++ if(substr($input, ($i + 15) % $len, 1) eq "*");
- $neighbours++ if(substr($input, ($i + 17) % $len, 1) eq "*");
if(substr($input, $cell, 1) eq "*") {
my $n = substr($death, $neighbours, 1);
substr($output, $cell, 1, $n);
@@ -76,13 +76,15 @@
;
my $j;
- my $gen = @ARGS[0] || 518;
- # for $j (0 .. 499) => imcc error releated to closure?
- print "Running " _ $gen _ " generations\n";
+ my $gen = @ARGS[0] || 100;
+ print "Running " , $gen , " generations\n";
Print($world);
+ my $ts = time();
loop( $j= 0 ; $j < $gen; $j++) {
$world = Generate($world)[0];
}
+ my $te = time();
Print($world);
+ print "Gens/s ", $gen/($te-$ts), "\n";
}