Commit 3dd22dd
fix: include number/2 divisor in FriendlyNumbers sumDivisors
sumDivisors looped 'for (let i = 0; i < number / 2; i++)', which excludes
i === number/2 -- a real divisor of every even number -- so the divisor
sum (and abundancy index) was wrong for even inputs, e.g. sumDivisors(6)
returned 9 instead of 12 and sumDivisors(28) returned 42 instead of 56.
That made FriendlyNumbers misclassify pairs (e.g. FriendlyNumbers(15, 20)
returned true though their abundancy indices differ).
Loop from 1 to number/2 inclusive. Added a test file (the module had none).1 parent 5c39e87 commit 3dd22dd
2 files changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
0 commit comments