diff options
| author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-10-09 16:15:48 -0500 |
|---|---|---|
| committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-10-09 16:16:29 -0500 |
| commit | c50ece109cdb29ab5d3fa7444040b546da7e360c (patch) | |
| tree | 33fbf5678f2030a85f6c4b4f20ff5fc302516c53 /factors/mtc.go | |
| parent | dbd02c8437ae634f4ece3c2979afeb19a3979f61 (diff) | |
factors: Give all exported members proper godoc
Diffstat (limited to 'factors/mtc.go')
| -rw-r--r-- | factors/mtc.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/factors/mtc.go b/factors/mtc.go index 024391e..4d40396 100644 --- a/factors/mtc.go +++ b/factors/mtc.go @@ -3,10 +3,21 @@ package factors // MTC returns the multiplication table complexity of a radix n. // This is an estimate of how difficult it is to learn a radix's // multiplication table. -func MTC(n uint32) uint64 { +// +// The MTC is a sum of each digit's row complexity, +// which is the length of the pattern of the product's last digit +// (equal to digit / gcd(digit, radix)). +// Digits 1 and radix - 1 are excluded because they have simpler patterns +// than the other digits. +// +// uint32 is used as the input type and uint64 as the output to prevent +// integer overflow (and because the MTC algorithm is slow). +// +// The MTC of 0 and 1 are both zero. +func MTC(radix uint32) uint64 { mtc := uint64(0) - for i := uint32(2); i <= n-2; i++ { - mtc += uint64(n / gcd(i, n)) + for digit := uint32(2); digit <= radix-2; digit++ { + mtc += uint64(radix / gcd(digit, radix)) } return mtc } |
