From b1babe9724561c20bc9a63a60b1bd590f9d5fde8 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 23 Jan 2011 14:28:23 +0300 Subject: Perl --- gcd.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 gcd.pl diff --git a/gcd.pl b/gcd.pl new file mode 100755 index 0000000..550f5f8 --- /dev/null +++ b/gcd.pl @@ -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); + -- cgit v1.2.3