summaryrefslogtreecommitdiff
path: root/gcd.pl
diff options
context:
space:
mode:
Diffstat (limited to 'gcd.pl')
-rwxr-xr-xgcd.pl14
1 files changed, 9 insertions, 5 deletions
diff --git a/gcd.pl b/gcd.pl
index 550f5f8..2975919 100755
--- a/gcd.pl
+++ b/gcd.pl
@@ -1,5 +1,9 @@
#!/usr/bin/env perl
+# Usage:
+# $ perl gcd.pl 11 22 33 121
+# 11
+
use strict;
use warnings;
use utf8;
@@ -7,15 +11,15 @@ use integer;
use List::Util qw/ reduce /;
sub gcd2 {
- my ($a, $b) = @_;
- $b == 0 ? $a : gcd2($b, $a % $b)
+ my ( $a, $b ) = @_;
+ $b == 0 ? $a : gcd2( $b, $a % $b );
}
# http://stackoverflow.com/questions/1490505/how-do-i-prevent-listmoreutils-from-warning-about-using-a-and-b-only-once
sub gcdn {
- our ($a, $b);
- reduce {gcd2($a, $b)} $_[0], @_
+ our ( $a, $b );
+ reduce { gcd2( $a, $b ) } 0, @_;
}
-print gcdn(@ARGV);
+print gcdn(@ARGV), "\n";