aboutsummaryrefslogtreecommitdiff
path: root/challenge-117/perlboy1967/perl/ch-1.pl
blob: a19af8d516ca6b13abe05f3afec89f7df4eed4e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl

# Perl Weekly Challenge - 117
# - https://perlweeklychallenge.org/blog/perl-weekly-challenge-117/#TASK1
#
# Task 1 - Missing Row(s)
#
# Author: Niels 'PerlBoy' van Dijke

use v5.16;
use strict;
use warnings;

use File::Basename qw(dirname);
use List::MoreUtils qw(slide);

my $input = $ARGV[0] // sprintf('%s/input.txt',dirname($0));

printf "Missing row number(s) of file '%s' is/are '%s'\n", 
       $input, join(',',missingRows($input));


sub missingRows {
  my ($f) = @_;
  
  open(my $fh,'<',$f) || die;

  return map { @$_ } slide {$b - $a > 1 ? [$a + 1 .. $b - 1] : [] }
                     sort { $a <=> $b }
                     map { /^(\d+)/; $_ = $1 }
                     <$fh>;
}