diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-07-09 11:08:21 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-07-09 11:08:21 +0300 |
commit | c70c0d4418ca756f9b6fc660d0aa9d54e6f025ae (patch) | |
tree | 2a538398d9607b3f7b2c4ee4601b7665ca6b482b | |
parent | 70135d54aafd032f94dfb4026d57a62d791d0706 (diff) | |
download | gcd-c70c0d4418ca756f9b6fc660d0aa9d54e6f025ae.tar.gz |
Update Perl
-rwxr-xr-x | gcd.pl | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -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"; |