Better output
This commit is contained in:
parent
22b72824b7
commit
8a03b835d8
1 changed files with 18 additions and 4 deletions
22
cellaut.pl
22
cellaut.pl
|
@ -2,6 +2,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use POSIX;
|
use POSIX;
|
||||||
|
use utf8;
|
||||||
|
binmode(STDOUT, ":utf8");
|
||||||
|
|
||||||
# Get arguments
|
# Get arguments
|
||||||
my $gens = $ARGV[0];
|
my $gens = $ARGV[0];
|
||||||
|
@ -61,6 +63,18 @@ sub set_up_init {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub print_arr {
|
||||||
|
foreach my $elem (values @_) {
|
||||||
|
if($elem) {
|
||||||
|
print " ";
|
||||||
|
} else {
|
||||||
|
print "■";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print "\n";
|
||||||
|
#sleep 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
# Print usage
|
# Print usage
|
||||||
sub usage {
|
sub usage {
|
||||||
print "$0 <number of generations> <width> <rule number (0-255)> [num rules]\n";
|
print "$0 <number of generations> <width> <rule number (0-255)> [num rules]\n";
|
||||||
|
@ -75,8 +89,8 @@ if (scalar @ARGV < 3 or $rule > $num_rules) {
|
||||||
|
|
||||||
# Get the initial condition and print it out
|
# Get the initial condition and print it out
|
||||||
my @initial = set_up_init;
|
my @initial = set_up_init;
|
||||||
print @initial;
|
print_arr @initial;
|
||||||
print "\n";
|
#print "\n";
|
||||||
|
|
||||||
# Now loop through all the generations
|
# Now loop through all the generations
|
||||||
for (my $gen = 0; $gen < $gens; $gen++) {
|
for (my $gen = 0; $gen < $gens; $gen++) {
|
||||||
|
@ -99,8 +113,8 @@ for (my $gen = 0; $gen < $gens; $gen++) {
|
||||||
# The next state is now the new initial
|
# The next state is now the new initial
|
||||||
@initial = @next;
|
@initial = @next;
|
||||||
# Print it out
|
# Print it out
|
||||||
print @initial;
|
print_arr @initial;
|
||||||
print "\n";
|
#print "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue