diff options
Diffstat (limited to 'challenge-201/dave-jacoby/perl/ch-1.pl')
| -rw-r--r-- | challenge-201/dave-jacoby/perl/ch-1.pl | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-201/dave-jacoby/perl/ch-1.pl b/challenge-201/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..6e23d10049 --- /dev/null +++ b/challenge-201/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +my @examples = ( + + [ 0, 1, 3 ], + [ 0, 1 ], + [ 1, 3, 5, 7, 9 ] + +); + +for my $e (@examples) { + my $list = join ',', $e->@*; + my @out = missing_numbers( $e->@* ); + my $out = join ',', @out; + say <<"END"; + Input: \@array = ($list) + Output: $out +END +} + +sub missing_numbers ( @array ) { + my $n = scalar @array; + my %h = map { $_ => 1 } @array; + my @output; + for my $v ( 0 .. $n ) { + push @output, $v unless $h{$v}; + } + return @output; +} |
