diff options
| author | Andrew Shitov <andy@shitov.ru> | 2020-12-04 09:17:37 +0100 |
|---|---|---|
| committer | Andrew Shitov <andy@shitov.ru> | 2020-12-04 09:17:37 +0100 |
| commit | fdd800775ca52e7600d78f38e5345a5197cc086c (patch) | |
| tree | 83e6da7d9535c716d29a57bab98f2a91cdcf4994 /challenge-089/ash/javascript/ch-1.js | |
| parent | d19b0f983bbefca06f6139624711c079ac18eb6e (diff) | |
| download | perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.tar.gz perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.tar.bz2 perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.zip | |
Week 89 Issue 1
Diffstat (limited to 'challenge-089/ash/javascript/ch-1.js')
| -rw-r--r-- | challenge-089/ash/javascript/ch-1.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-089/ash/javascript/ch-1.js b/challenge-089/ash/javascript/ch-1.js new file mode 100644 index 0000000000..c090b44808 --- /dev/null +++ b/challenge-089/ash/javascript/ch-1.js @@ -0,0 +1,24 @@ +// Test run: +// $ node ch-1.js 100 +// 13015 + +let n = process.argv.length == 3 ? process.argv[2] : 3; + +let s = 0; +for (let x = 1; x <= n; x++) { + for (let y = x + 1; y <= n; y++) { + s += gcd(x, y); + } +} + +console.log(s); + +function gcd(a, b) { + while (b) { + let t = b; + b = a % b; + a = t; + } + + return a; +} |
