diff options
Diffstat (limited to 'factor_info.go')
| -rw-r--r-- | factor_info.go | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/factor_info.go b/factor_info.go index 03c81f3..bcfc3b1 100644 --- a/factor_info.go +++ b/factor_info.go @@ -26,6 +26,8 @@ type factorInfo struct { // The fraction of digits that are totatives (numbers that share no // factors with the radix - they are the worst kind of digits) TotativeRatio float64 + // The totative digits of this radix. May be nil if this was not requested. + TotativeDigits []uint32 // A rank measuring how well the radix works with the most elementary // numbers and ratios BasicRank string @@ -58,18 +60,25 @@ const ( maxExtended = 1 << 32 ) -func getFactorInfo(radix uint, fullMap bool, exactMTCLarge bool) *factorInfo { +func getFactorInfo(a args) *factorInfo { + radix := a.Radix + r_factors := factors.Factors(radix) slices.Sort(r_factors) + var totativeDigits []uint32 = nil + if a.TotativeDigits && radix < maxExtended { + totativeDigits = factors.TotativeDigits(uint32(radix)) + } + var mtc_ptr *uint64 = nil - if radix < maxNormal || (exactMTCLarge && radix < maxExtended) { + if radix < maxNormal || (a.ExactMTCLarge && radix < maxExtended) { mtc := factors.MTC(uint32(radix)) mtc_ptr = &mtc } var digitMap []factors.DigitType - if fullMap { + if a.FullMap { digitMap = make([]factors.DigitType, maxSmallRadix) for d := 0; d < maxSmallRadix; d++ { digitMap[d] = factors.GetDigitType(uint(d), radix) @@ -85,16 +94,21 @@ func getFactorInfo(radix uint, fullMap bool, exactMTCLarge bool) *factorInfo { return &factorInfo{radix, factors.PrimeFactorize(radix), r_factors, factors.Score(radix), totativeCount, totativeRatio, - factors.BasicRank(radix), factors.Type(radix), mtc_ptr, - math.Log(float64(radix)), digitMap} + totativeDigits, factors.BasicRank(radix), factors.Type(radix), + mtc_ptr, math.Log(float64(radix)), digitMap} } func (fi *factorInfo) writeTo(w io.Writer) { fmt.Fprintln(w, fi.Radix, "=", fi.PrimeFactorization) fmt.Fprintf(w, "Factors: %v (Score: %.4f)\n", fi.Factors, fi.Score) fmt.Fprintln(w, "2345 Rank:", fi.BasicRank) - fmt.Fprintf(w, "Totative Digit Count: %d (%.3f%%)\n", - fi.Totient, fi.TotativeRatio*100.0) + if fi.TotativeDigits != nil { + fmt.Fprintf(w, "Totative Digits: %v (%.3f%%)\n", + fi.TotativeDigits, fi.TotativeRatio*100.0) + } else { + fmt.Fprintf(w, "Totative Digit Count: %d (%.3f%%)\n", + fi.Totient, fi.TotativeRatio*100.0) + } writeTypeMessage(w, fi.Type) if fi.MTC != nil { fmt.Fprintln(w, "Multiplication Table Complexity:", *fi.MTC) |
