Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: Faster alternative to Math::Combinatorics

by AppleFritter (Vicar)
on Sep 01, 2017 at 16:46 UTC ( #1198532=note: print w/replies, xml ) Need Help??

in reply to Re: Faster alternative to Math::Combinatorics
in thread Faster alternative to Math::Combinatorics

Depending on how many elements you have :)

Good question! The number could be arbitrarily high in theory, in practice I doubt the number will leave the two-digit range¹. (In case anyone's wondering, BTW, this is related to multistate cellular automata; w is a neighborhood count, and the list I mentioned is a list of (some) states of the CA in question.)

I'll have to take a long look at your code to really understand it, but wow, those timings look marvellous. Thank you! If this ends up working out I'll definitely owe you a beer.


  1. Edited to add: in fact, since the amount of data generated will increase exponentially with the number of CA states, I think realistically, it won't even leave the single-digit range.
  • Comment on Re^2: Faster alternative to Math::Combinatorics

Replies are listed 'Best First'.
Re^3: Faster alternative to Math::Combinatorics
by tybalt89 (Monsignor) on Sep 01, 2017 at 17:36 UTC

    Here's a version of the same algorithm working on array elements instead of characters. (Messier, isn't it?)

    With 10 elements (states) it takes 1.5 seconds on my machine, but I think most of the time is taken by the printing.

    How many neighbors can you have? (for code testing purposes.)

    #!/usr/bin/perl -l # use strict; use warnings; my @elements = (0, 2, 3); @elements = 0..9; my ($first, $last) = @elements[0, -1]; my %next; @next{@elements} = @elements[1 .. $#elements]; for my $count (1,2,3,4,7,8) { print "count=$count"; my @set = ($first) x $count; local $, = ','; while(1) { print @set; my $i = $#set; $i-- while $i >= 0 and $set[$i] eq $last; $i < 0 and last; @set[$i .. $#set] = ($next{$set[$i]}) x ( @set - $i); } }

      How many neighbors can you have? (for code testing purposes.)

      A maximum of eight — the size of the range-1 Moore neighborhood, as I'm not currently considering CAs with larger neighborhoods.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1198532]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2023-03-25 15:05 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (63 votes). Check out past polls.