Skip to content

Commit dbdc30b

Browse files
committed
improve comments/docs in wk-081 ch-1
1 parent fa79198 commit dbdc30b

File tree

1 file changed

+30
-16
lines changed
  • challenge-082/alexander-pankoff/perl

1 file changed

+30
-16
lines changed

challenge-082/alexander-pankoff/perl/ch-1.pl

+30-16
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,22 @@
1212
use List::Util qw(min all any);
1313
use Scalar::Util qw(looks_like_number);
1414

15-
=pod
16-
17-
=head1 SYNOPSIS
18-
19-
This Script will print a list of common factors from M and N
20-
21-
=head1 USAGE
22-
23-
ch-1.pl <M> <N>
24-
25-
=cut
26-
2715
pod2usage(
28-
-message => "$0: Expects 2 postive numbers",
29-
-exitval => 1,
30-
-verbose => 99,
31-
-sections => "USAGE|SYNOPSIS",
16+
-message => "$0: Expects 2 natural numbers",
17+
-exitval => 1,
3218
)
3319
if @ARGV != 2
3420
or any { !looks_like_number($_) || $_ < 1 } @ARGV;
3521

3622
my ( $M, $N ) = @ARGV;
23+
3724
say format_list( common_factors( $M, $N ) );
3825

3926
sub common_factors ( $m, $n ) {
27+
28+
# we grep for numbers from 1 to min($m,$n) that are factors of both $m and
29+
# $n. since all numbers larger than min($m,$n) can't be a factor of that
30+
# minimum we don't have to check them
4031
grep {
4132
my $check_factor = $_;
4233
all { is_factor( $check_factor, $_ ) } ( $m, $n );
@@ -51,3 +42,26 @@ (@list)
5142
return '(' . join( ', ', @list ) . ')';
5243
}
5344

45+
=pod
46+
47+
=head1 NAME
48+
49+
wk-082 ch-1 - Common Factors
50+
51+
=head1 SYNOPSIS
52+
53+
Prints the common factors of two given natural numbers M and N
54+
55+
ch-1.pl <M> <N>
56+
57+
=head1 ARGUMENTS
58+
59+
=over 8
60+
61+
=item B<N> The first natural number
62+
63+
=item B<M> The second natural number
64+
65+
=back
66+
67+
=cut

0 commit comments

Comments
 (0)