diff options
author | Igor <pashev.igor@gmail.com> | 2011-01-23 14:28:23 +0300 |
---|---|---|
committer | Igor <pashev.igor@gmail.com> | 2011-01-23 14:28:23 +0300 |
commit | b1babe9724561c20bc9a63a60b1bd590f9d5fde8 (patch) | |
tree | c13064c4e9c90340ddcc48b362aba1930378bb83 | |
parent | 9e677082cfd5af8d0ac76672784cc00ecaa3ed1a (diff) | |
download | gcd-b1babe9724561c20bc9a63a60b1bd590f9d5fde8.tar.gz |
Perl
-rwxr-xr-x | gcd.pl | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -0,0 +1,21 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; +use integer; +use List::Util qw/ reduce /; + +sub gcd2 { + 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], @_ +} + +print gcdn(@ARGV); + |