3 # life.pl adopted for perl6 after:
9 # // Copyright (C) 2002 Melvin Smith
12 # (c) 2002 by Leopold Toetsch
14 # Input / output are int arrays - slooow - needs a rewrite
16 sub print_world
($world) {
17 for ($world) -> $row {
18 say $row.map: { +$_ ??
'*' !! ' '}.join("");
20 say "----------------";
23 sub neighbors
($cell_x, $cell_y, $input) {
25 for -1,0,1 -> $x_off {
26 for -1,0,1 -> $y_off {
27 $neighbors += $input[$cell_x + $x_off][$cell_y + $y_off];
35 my @death = (0,0,1,1,0,0,0,0,0);
40 my $neighbors = neighbors
($x,$y,$input);
42 if (@death[$neighbors]) {
50 if ($neighbors == 3) {
61 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
62 [0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
63 [0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,],
64 [1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,],
65 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
66 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
67 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
68 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
69 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
70 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
71 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
72 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,],
73 [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,],
74 [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,],
75 [0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,],
76 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
79 my $gen = @
*ARGS
[0] || 100;
80 say "Running ", $gen, " generations";
85 $world = sycle
($world);
87 my $tdelta = time() - $ts + 1;
89 my $ratio = $gen / $tdelta;
90 say "Gens/s: ", $ratio;