aboutsummaryrefslogtreecommitdiff
path: root/challenge-089/ash/php/ch-1.php
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-089/ash/php/ch-1.php')
-rw-r--r--challenge-089/ash/php/ch-1.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-089/ash/php/ch-1.php b/challenge-089/ash/php/ch-1.php
new file mode 100644
index 0000000000..9209076d61
--- /dev/null
+++ b/challenge-089/ash/php/ch-1.php
@@ -0,0 +1,27 @@
+<?php
+ // Run as:
+ // $ php ch-1.php 100
+ // 13015
+
+ function gcd($a, $b) {
+ while ($b) {
+ $t = $b;
+ $b = $a % $b;
+ $a = $t;
+ }
+
+ return $a;
+ }
+
+ $n = $argc == 2 ? $argv[1] : 3;
+
+ $s = 0;
+ for ($x = 1; $x <= $n; $x++) {
+ for ($y = $x + 1; $y <= $n; $y++) {
+ $s += gcd($x, $y);
+ }
+ }
+
+ echo "$s\n";
+
+?>