summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2013-12-21 11:45:47 +0400
committerIgor Pashev <pashev.igor@gmail.com>2013-12-21 11:45:47 +0400
commitf9787e0c62fda6dbc1027776cdf1515622b974a2 (patch)
treede59418874ecabe546a4a2bbdb19557c59073b3a
parent4b5bdac9bd93ac97e3f99a14d3d28a70cd33607c (diff)
downloadgcd-f9787e0c62fda6dbc1027776cdf1515622b974a2.tar.gz
PHP
-rw-r--r--gcd.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/gcd.php b/gcd.php
new file mode 100644
index 0000000..0ab0871
--- /dev/null
+++ b/gcd.php
@@ -0,0 +1,28 @@
+<?php
+
+function gcd2($a, $b)
+{
+ $c = 0;
+ while ($b != 0)
+ {
+ $c = $b;
+ $b = $a % $b;
+ $a = $c;
+ }
+ return $a;
+}
+
+function gcd($numbers)
+{
+ $r = 0;
+ foreach ($numbers as $n)
+ {
+ $r = gcd2($n, $r);
+ }
+ return $r;
+}
+
+print gcd(array_slice($argv, 1));
+
+?>
+