aboutsummaryrefslogtreecommitdiff
path: root/challenge-089/henry-wong/php/ch-1.php
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-089/henry-wong/php/ch-1.php')
-rw-r--r--challenge-089/henry-wong/php/ch-1.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-089/henry-wong/php/ch-1.php b/challenge-089/henry-wong/php/ch-1.php
new file mode 100644
index 0000000000..4303a961b3
--- /dev/null
+++ b/challenge-089/henry-wong/php/ch-1.php
@@ -0,0 +1,24 @@
+<?php
+
+function gcd($a, $b) {
+ // could of used https://www.php.net/manual/en/function.gmp-gcd.php
+ return ($a % $b) ? gcd($b,$a % $b) : $b;
+}
+function solutions($N) {
+ // $N can't be less than 2
+ if ($N <= 1) {
+ return false;
+ }
+ $total = 0;
+ for ($i = 1; $i <= $N; $i++) {
+ for ($next = $i + 1; $next <= $N; $next++) {
+ // debug purpose
+ printf ("gcd(%s, %s)\n", $i, $next);
+ $total += gcd($i, $next);
+ }
+ }
+ return $total;
+}
+
+echo solutions(3), "\n";
+echo solutions(4), "\n"; \ No newline at end of file