summaryrefslogtreecommitdiff
path: root/factors/prime_factorization.go
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-08-23 15:55:54 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-08-23 16:26:21 -0500
commit24a8dde3a708b0cd95007d940e8957b21df40055 (patch)
tree6d4036fd427f4e36651bc0237a0a1e9b74d36155 /factors/prime_factorization.go
parentdc00f5c20b62de58dbad4b71792632599528c19f (diff)
Add radix type to output
This type measures which kind of classes each radix is a part of: - Colossally Abundant (OEIS: A004490; factor score better than every other number if you account for size be dividing by a certain power of the number) - Superabundant (OEIS: A004394; factor score better than every smaller number) - Ordered-Exponent (OEIS: A025487; exponents in prime factorization go down as you get to bigger primes, and no prime is skipped) - Practical (OEIS: A005153; factors can sum to any number below the original number without duplication) Each of these groups is a subset of the next, so only the most specific label is reported. The purpose of this program is to give you useful info to help you determine which radices are the best, and these categories give a rough, quantitative measure of how useful a radix's factors are: - Practical is approximately the minimum requirement for a worthwhile radix. Non-practical radices above ~16 are probably terrible to use. - Ordered-Exponent radices act like local maxima - you can't get any better (smaller) without changing the "shape" (exponents) of your prime factorization. - Superabundant radices are the best radices below the next superabundant number (e.g. 12 is the best radix below 24). - Colossally abundant radices are, in some sense, the best radices out of all numbers.
Diffstat (limited to 'factors/prime_factorization.go')
-rw-r--r--factors/prime_factorization.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/factors/prime_factorization.go b/factors/prime_factorization.go
index 69d0e08..f91a2cf 100644
--- a/factors/prime_factorization.go
+++ b/factors/prime_factorization.go
@@ -45,7 +45,7 @@ func (factors PrimeFactorization) Exponent(p uint) uint {
return factors.exponents[p]
}
-// ExponentMap creates and returns a map mapping primes to their exponents.
+// ExponentMap returns a map mapping primes to their exponents.
func (factors PrimeFactorization) ExponentMap() map[uint]uint {
exponentMap := make(map[uint]uint, len(factors.exponents))
for p, e := range factors.exponents {
@@ -54,6 +54,17 @@ func (factors PrimeFactorization) ExponentMap() map[uint]uint {
return exponentMap
}
+// Primes returns a slice containing all of the primes with nonzero exponents
+func (factors PrimeFactorization) Primes() []uint {
+ primes := make([]uint, 0, len(factors.exponents))
+ for p := range factors.exponents {
+ if factors.exponents[p] > 0 {
+ primes = append(primes, p)
+ }
+ }
+ return primes
+}
+
// Size returns how many primes in this factorization have nonzero exponents.
func (factors PrimeFactorization) Size() int {
return len(factors.exponents)