### Comment on

 Need Help??
I like the idea. Here's my attempt: I've tried to use a few more of the advanced features...
```#!/usr/bin/perl6

given new life(dimension => 20)
{
for 1..Inf -> \$count
{
.display();
print "TURN \$count, press enter for next turn, ctl-c to quit";
<\$*STDIN>;
.calculate();
}
}

class life
{
has int \$.dimension;

has @.grid is dim(\$.dimension, \$.dimension)
is base_index(\$.dimension/2, \$.dimension/2)
of bit is default(0)
is str {<< - + >>[\$_]};

method BUILD(\$.dimension)
{
for (-1, 0), (-1, 1), (0, 0), (0, -1), (1, 0) -> \$x, \$y
{
@.grid[\$y][\$x] = 1;
}
}

method will_live(int \$y, int \$x) returns bool is private
{
my \$neighborhood = @.grid[\$y+(-1|0|+1)][\$x+(-1|0|+1)];
my \$alive = sum(\$neighborhood.elems);

@.grid[\$y][\$x] ?? 1 < \$alive-1 < 4 :: \$alive == 3;
}

method calculate
{
my @new_grid is like @.grid;
for @new_grid.kv -> \$y, @new_row is rw
{
for @row.kv -> \$x, \$new_cell is rw
{
\$new_cell = .will_live(\$y,\$x) ?? 1 :: 0;
}
}
@.grid = @new_grid;
}

method display
{
for @.grid -> @row
{
print @row, "\n";
}
}
}
--Dave

Update: I'm pretty sure the junction I gave for the neighborhood won't work: here's an improved will_live method:

```    method will_live(int \$y, int \$x) returns bool
{
my \$offsets = [-1|0|+1 , -1|0|+1] & none([0,0]);
my @neighbors = (\$offsets >>+<< [\$y,\$x]).states;
my @cells = @neighbors.map {@.grid[\$_[0]][\$_[1]]};
my \$alive = @cells.sum;

@.grid[\$y][\$x] ?? \$alive == 2|3 :: \$alive == 3;
}
Still too much line noise though. There must be a simpler way.
Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2018-02-18 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When it is dark outside I am happiest to see ...

Results (253 votes). Check out past polls.

Notices?