03:07 sivoais left 03:08 sivoais joined 06:42 kurahaupo left 17:05 human-blip left 17:07 human-blip joined 20:05 disbot left, disbot joined
disbot <ilguappo> I'm curious why this code is so slow. It takes more than a second for a 36x90 terminal window raku sub neighbors([$x, $y]) { ([-1,0,1] X [-1,0,1]) .grep({$_[0] != 0 || $_[1] != 0}) .map({$_[0] + $x, $_[1] + $y}).Slip } sub frequencies(@board) { @board.sort() .unique(:with(&infix:<eqv>)) .map(-> $x { ( $x, @board.grep( {$_[0] == $x[0] && $_[1] == $x[1]} ).elems) }); } sub 21:30
step(@board) { frequencies(@board.map({neighbors $_})) .grep({ ($_[1] == 3) or ( @board.grep(* eqv $_[0]) and ($_[1] == 2)) }) .map({$_[0]}); }
<ilguappo> Frequencies is quadratic right? But still 21:31
<ilguappo> I got the algorithm from strangeleaflet.com/conways-game-of...-approach/ 21:32
<antononcube> Hm... I have been seriously considering for weeks to create the package "CellularAutomata". And use it to play with Conway's Game of Life on different types of grids. 21:42
<antononcube> This brings two questions: 1. To what extend rule-based programming should be implemented in Raku? 2. Can 1D and 2D Cellular Automata (CA) be implemented using sparse matrices? 21:45
<antononcube> I think the answer of the 2nd question is "yes", hence, the a much faster implementation of Game of Life can be done in Raku. 21:47
<ilguappo> I have a version using a sparse hash map. I'm just using GOL to learn aspects of Raku. It is much faster
<antononcube> Yeah, sparse matrix algebra can be implemented with hashmaps. 21:48
<ilguappo> The above algorithm is sparse. It's only storing and manipulating a list of alive cells and potentially alive cells 21:49
<ilguappo> That's why I'm confused as to why it's unbearably slow on such a small grid. 21:50
<antononcube> Ok. I am proposing / looking into sparse matrices because "Math::SparseMatrix" can use C-implemented matrix algebra. 21:51
<antononcube> Especially with large play fields that should be fairly fast. 21:52
<ilguappo> That's interesting. 21:53
<ilguappo> This is what inspired me to use GOL to learn programming languages. jaxry.github.io/colorful-life/ 21:57
<antononcube> Nice! Also, it can be implemented in Raku.
<antononcube> Hmm.. if the mutation rules can be expressed as sparse matrix operations. 21:58
<antononcube> "Dry life" 🙂 21:59
<antononcube> @ilguappo In case you are wonder why I am interested in Cellular Automata -- I tend to talk the "New Kind of Science" guy often enough. 22:02
<antononcube> This seems like a good topic to discuss at «The SF Perl Raku Study Group, 08/09 at 1pm PDT». 22:15
<antononcube> @ilguappo Can GOL be implemented using regexes? That should be fast. 22:34
<ilguappo> That's an interesting idea. I don't know. 22:46
<ilguappo> I found this code golf version and of course Perl wins. 😉 stackoverflow.com/a/3539261 22:51
<ilguappo> I can't say I understand that it all. Lol 22:52
<ilguappo> Cool stuff dotat.at/prog/life/life.html 23:03
23:23 kurahaupo joined