diff options
| author | dasJake <no_mail@github.com> | 2021-12-10 15:07:11 +0100 |
|---|---|---|
| committer | dasJake <no_mail@github.com> | 2021-12-10 15:19:36 +0100 |
| commit | 5dd233be0cc765ce4d6ddf75ad80faf87d8955d3 (patch) | |
| tree | e28245a0baa839c1f80293744b11f3821f2a314f /challenge-142 | |
| parent | 5601ab5c5b3cde0c5bfe35d0beee22625e6cf0d6 (diff) | |
| download | perlweeklychallenge-club-5dd233be0cc765ce4d6ddf75ad80faf87d8955d3.tar.gz perlweeklychallenge-club-5dd233be0cc765ce4d6ddf75ad80faf87d8955d3.tar.bz2 perlweeklychallenge-club-5dd233be0cc765ce4d6ddf75ad80faf87d8955d3.zip | |
142 minor refactor
Diffstat (limited to 'challenge-142')
| -rwxr-xr-x | challenge-142/jake/perl/ch-1.pl | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/challenge-142/jake/perl/ch-1.pl b/challenge-142/jake/perl/ch-1.pl index 8c2544489a..c18257da47 100755 --- a/challenge-142/jake/perl/ch-1.pl +++ b/challenge-142/jake/perl/ch-1.pl @@ -18,15 +18,16 @@ my $last_dig = <STDIN>; chomp $last_dig; # output -my @res = count_divisors( 1, $num ); -my @rres = filter_last_digit ( $last_dig, \@res ); -say scalar ( @rres ); +my @divisors = count_divisors( 1, $num ); +my @res = filter_last_digit ( $last_dig, \@divisors ); +say scalar ( @res ); # collect numbers with specific last digit sub filter_last_digit { - my ( $last_dig, $res ) = @_; + my ( $last_dig, $divisors ) = @_; - my @result = grep { substr( $_, -1 ) == $last_dig } @$res ; + # courtesy ccntrq + my @result = grep { substr( $_, -1 ) == $last_dig } @$divisors ; return @result; } @@ -43,6 +44,6 @@ sub count_divisors { } #according to the task the number itself is not considered a divisor, so we cut it off of the result - splice( @divisors, $#divisors, 1 ); + splice( @divisors, -1 ); return @divisors; }
\ No newline at end of file |
