From 26384c15d3b4f63770fccff0b4075feebbe00bba Mon Sep 17 00:00:00 2001 From: Mikael Nordin Date: Sat, 29 Oct 2016 01:20:45 +0200 Subject: [PATCH] Handle boundaries by modulo instead --- cellaut.pl | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/cellaut.pl b/cellaut.pl index 1cf3425..6003c83 100755 --- a/cellaut.pl +++ b/cellaut.pl @@ -97,16 +97,9 @@ for (my $gen = 0; $gen < $gens; $gen++) { # This is the next evoultion of the the automation my @next; for (my $elem = 0; $elem < $width ; $elem++) { - # Boundary conditions - my $state; - if($elem == 0 ) { - $state = $initial[$width -1] . $initial[$elem] . $initial[$elem +1 ] ; - } elsif ($elem == $width -1 ) { - $state = $initial[$elem-1] . $initial[$elem] . $initial[0]; - # Normal, we are not on the boundary - } else { - $state = $initial[$elem - 1] . $initial[$elem] . $initial[$elem +1]; - } + # Boundary conditions handled by modulo so we wrap around + my $state = $initial[$elem - 1 % $width] . $initial[$elem] . $initial[$elem +1 % $width]; + # Get the corresponding value for this state $next[$elem] = get_val_at_pos oct("0b".$state); }