Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created March 20, 2014 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/9670877 to your computer and use it in GitHub Desktop.
Save grondilu/9670877 to your computer and use it in GitHub Desktop.
class Automaton {
my sub B($x) { 1 +< $x }
has uint $.rule;
has uint64 $.state;
method gist { $!state.fmt("%064b").flip }
method succ {
loop (my uint64 $st = my $i = 0; $i < 64; $i++) {
if ($!rule +& B(7 +& (($!state +> ($i - 1)) +| ($!state +< (65 - $i))))) {
$st = $st +| B($i);
}
}
self.new: :$!rule, :state($st);
}
}
my Automaton $a .= new: :rule(90), :state( 1 );
say $a++ for ^10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment