diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-12-06 11:28:41 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-06 11:28:41 +0000 |
| commit | e1fa520a5aee78c1d8c6daaaa232216183047ec8 (patch) | |
| tree | 7f490b425e24c13a87a34a9a5c15b8b3ae2d142b /challenge-089/ash/php | |
| parent | 37f7a8fdda722a8df258f11676317dfa9b4eabba (diff) | |
| parent | b0f91205a62dd4131e60d6ce1a8947cfe04b76a2 (diff) | |
| download | perlweeklychallenge-club-e1fa520a5aee78c1d8c6daaaa232216183047ec8.tar.gz perlweeklychallenge-club-e1fa520a5aee78c1d8c6daaaa232216183047ec8.tar.bz2 perlweeklychallenge-club-e1fa520a5aee78c1d8c6daaaa232216183047ec8.zip | |
Merge pull request #2915 from ash/master
Week 89 Task 1 and an Advent blog post
Diffstat (limited to 'challenge-089/ash/php')
| -rw-r--r-- | challenge-089/ash/php/ch-1.php | 27 |
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"; + +?> |
