diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-01-11 06:16:46 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-01-11 06:16:46 +0000 |
| commit | f7d69a81862d0ff686fefd288191c26f2e153803 (patch) | |
| tree | 5a584a9b56fd79ea806c48cfcf3175ee05540cb3 /challenge-147/roger-bell-west/javascript/ch-2.js | |
| parent | 80a1b64153ca8fcde1b2f59b98fd21ecf0ac716a (diff) | |
| parent | d5aef342008aa2a96e8085194e3a3dc6975a723b (diff) | |
| download | perlweeklychallenge-club-f7d69a81862d0ff686fefd288191c26f2e153803.tar.gz perlweeklychallenge-club-f7d69a81862d0ff686fefd288191c26f2e153803.tar.bz2 perlweeklychallenge-club-f7d69a81862d0ff686fefd288191c26f2e153803.zip | |
vi ch-1.plMerge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-147/roger-bell-west/javascript/ch-2.js')
| -rwxr-xr-x | challenge-147/roger-bell-west/javascript/ch-2.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-147/roger-bell-west/javascript/ch-2.js b/challenge-147/roger-bell-west/javascript/ch-2.js new file mode 100755 index 0000000000..2cbfbc98a8 --- /dev/null +++ b/challenge-147/roger-bell-west/javascript/ch-2.js @@ -0,0 +1,38 @@ +#! /usr/bin/node + +function pentagon(n) { + return Math.floor(n*(3*n-1)/2); +} + +function pentpair() { + let fpent=[0]; + let rpent=new Map(); + let mx=0; + let a=1; + while (true) { + while (mx < a) { + mx++; + fpent.push(pentagon(mx)); + rpent.set(fpent[mx],mx); + } + for (b = 1; b < a; b++) { + let d=fpent[a]-fpent[b]; + if (rpent.has(d)) { + let s=fpent[a]+fpent[b]; + while (s > fpent[mx]) { + mx++; + fpent.push(pentagon(mx)); + rpent.set(fpent[mx],mx); + } + if (rpent.has(s)) { + console.log("P(%d) + P(%d) = %d + %d = %d = P(%d)",a,b,fpent[a],fpent[b],s,rpent.get(s)); + console.log("P(%d) - P(%d) = %d - %d = %d = P(%d)",a,b,fpent[a],fpent[b],d,rpent.get(d)); + throw ''; + } + } + } + a++; + } +} + +pentpair(); |
