aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobbie-hatley <Robbie.Hatley@gmail.com>2023-03-31 23:30:22 -0700
committerrobbie-hatley <Robbie.Hatley@gmail.com>2023-03-31 23:30:22 -0700
commit919379dab5635275f741a6099b18dec457ecb9ac (patch)
tree72b6e198d9d149949ea193c6fc9530d3b6f26fbe
parent6754d8587ff5edb536c6f26869f168edc5422064 (diff)
downloadperlweeklychallenge-club-919379dab5635275f741a6099b18dec457ecb9ac.tar.gz
perlweeklychallenge-club-919379dab5635275f741a6099b18dec457ecb9ac.tar.bz2
perlweeklychallenge-club-919379dab5635275f741a6099b18dec457ecb9ac.zip
Did some fine-tuning.
-rwxr-xr-xchallenge-210/robbie-hatley/perl/ch-1.pl12
-rwxr-xr-xchallenge-210/robbie-hatley/perl/ch-2.pl12
2 files changed, 12 insertions, 12 deletions
diff --git a/challenge-210/robbie-hatley/perl/ch-1.pl b/challenge-210/robbie-hatley/perl/ch-1.pl
index 56d2d66996..2c84a11137 100755
--- a/challenge-210/robbie-hatley/perl/ch-1.pl
+++ b/challenge-210/robbie-hatley/perl/ch-1.pl
@@ -67,16 +67,16 @@ for (@arrays){
# Announce original integer list:
say '';
- say "Integer list: (@{$_})";
+ say "Integer list: (@$_)";
# Remove all positive integers from list, but take note if we remove
# any 1s:
my @removed = ();
my $one = 0;
- for ( my $i = 0 ; $i < scalar(@{$_}) ; ++$i ){
+ for ( my $i = 0 ; $i <= $#$_ ; ++$i ){
if ( $_->[$i] > 0 ){
if ( $_->[$i] == 1 ){$one = 1;}
- push @removed, splice @{$_}, $i, 1;
+ push @removed, splice @$_, $i, 1;
--$i;
}
}
@@ -85,9 +85,9 @@ for (@arrays){
# "manually removing any number x automatically removes all x-1
# and x+1" rule:
if ( $one ){
- for ( my $i = 0 ; $i < scalar(@{$_}) ; ++$i ){
+ for ( my $i = 0 ; $i <= $#$_ ; ++$i ){
if ( $_->[$i] == 0 ){
- push @removed, splice @{$_}, $i, 1;
+ push @removed, splice @$_, $i, 1;
--$i;
}
}
@@ -95,7 +95,7 @@ for (@arrays){
# Announce numbers removed and remnants of original array:
say "Removed: (@removed)";
- say "Remaining: (@{$_})";
+ say "Remaining: (@$_)";
# Calculate and announce final score:
say "Max points: ", sum0(@removed);
diff --git a/challenge-210/robbie-hatley/perl/ch-2.pl b/challenge-210/robbie-hatley/perl/ch-2.pl
index 527cb2f38a..9264c393c6 100755
--- a/challenge-210/robbie-hatley/perl/ch-2.pl
+++ b/challenge-210/robbie-hatley/perl/ch-2.pl
@@ -89,33 +89,33 @@ say 'Let the integer collisions commence.';
for (@arrays){
# Announce original integer list:
say '';
- say "Integer list: (@{$_})";
+ say "Integer list: (@$_)";
# Riffle through the list, generally going from left to right, but
# backtracking as necessary to chase "sinking" negatives and process
# their collisions:
- for ( my $i = 1 ; $i <= $#{$_} ; ++$i ){
+ for ( my $i = 1 ; $i <= $#$_ ; ++$i ){
next if $i < 1; # This may happen if we destroy both prev and curr
# Are previous and current about to collide?
if ( $_->[$i-1] >= 0 && $_->[$i] < 0 ){
# If previous has greater absolute value, destroy current only:
if ( $_->[$i-1] > -$_->[$i] ){
- splice @{$_}, $i, 1;
+ splice @$_, $i, 1;
--$i; # Backtrack 1 because removed current item.
}
# If previous and current have equal absolute value, destroy both:
elsif ( $_->[$i-1] == -$_->[$i] ){
- splice @{$_}, $i-1, 2;
+ splice @$_, $i-1, 2;
--$i; --$i; # Backtrack 2 because removed previous and current items.
}
# If current has greater absolute value, destroy previous only:
elsif ( $_->[$i-1] < -$_->[$i] ){
- splice @{$_}, $i-1, 1;
+ splice @$_, $i-1, 1;
--$i; --$i; # Backtrack 2 because removed previous item.
}
}
}
# Announce remnants of original array:
- say "Remaining: (@{$_})";
+ say "Remaining: (@$_)";
}