aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-117/steven-wilson/perl/ch-1.pl24
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";