diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-06-16 13:46:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-16 13:46:58 +0100 |
| commit | 46f5012d2acd46d552449be4b4b089ef1b8b93ca (patch) | |
| tree | eb4089a75c11a91550f4eed893b0e9eb739f5fe7 | |
| parent | 69bd9c4c232b7856e3ebb82f442b95cc81ad9baa (diff) | |
| parent | 897c5dfecb15383680ec3d5c2c77a6c185a9729c (diff) | |
| download | perlweeklychallenge-club-46f5012d2acd46d552449be4b4b089ef1b8b93ca.tar.gz perlweeklychallenge-club-46f5012d2acd46d552449be4b4b089ef1b8b93ca.tar.bz2 perlweeklychallenge-club-46f5012d2acd46d552449be4b4b089ef1b8b93ca.zip | |
Merge pull request #4278 from oWnOIzRi/week117
add perl solution for task 1
| -rwxr-xr-x | challenge-117/steven-wilson/perl/ch-1.pl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-117/steven-wilson/perl/ch-1.pl b/challenge-117/steven-wilson/perl/ch-1.pl new file mode 100755 index 0000000000..10cbdf1b2e --- /dev/null +++ b/challenge-117/steven-wilson/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl +# usage: $ ./ch-1.pl file_with_missing_row.txt + +use strict; +use warnings; +use feature qw/ say /; +use List::Util qw/ sum /; + +my $filename = $ARGV[0]; + +open(my $fh, '<', $filename) + or die "Can't open $filename: @!"; + +my @row_numbers; +while (my $row = <$fh>){ + push @row_numbers, (split /,/, $row )[0]; +} + +my $sum_of_row_numbers = sum(@row_numbers); +my $sum_of_row_range = sum(1 .. (@row_numbers + 1)); + +my $missing_row = $sum_of_row_range - $sum_of_row_numbers; + +say "The missing row number is $missing_row"; |
