summaryrefslogtreecommitdiff
path: root/radix_info.go
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-08-30 16:20:50 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-08-30 20:02:26 -0500
commit32320351ec98bbdf526d1587d073e4f3a382f2d5 (patch)
tree683dc167f2993f3da75e9fa5c0cfabe92e94d36c /radix_info.go
parent347e49fba8dc1f9ec01c18fe35628a35e1432f1e (diff)
Extract factor info into separate struct
This achieves two things: - Decouples my code by putting the printing code into its own file - Makes it easier to make alternate ways of printing (e.g. a compact mode)
Diffstat (limited to 'radix_info.go')
-rw-r--r--radix_info.go38
1 files changed, 2 insertions, 36 deletions
diff --git a/radix_info.go b/radix_info.go
index 20cbc20..32e1e40 100644
--- a/radix_info.go
+++ b/radix_info.go
@@ -1,11 +1,8 @@
package main
import (
- "aphopkins/radix_info/factors"
"fmt"
- "math"
"os"
- "slices"
"strconv"
)
@@ -13,26 +10,8 @@ func main() {
if len(os.Args) > 1 {
if n, err := strconv.ParseUint(os.Args[1], 0, 0); err == nil {
if n > 1 {
- n := uint(n)
- fmt.Println(n, "=", factors.PrimeFactorize(n))
- n_factors := factors.Factors(n)
- slices.Sort(n_factors)
- factorScore := factors.Score(n)
- fmt.Printf("Factors: %v (Score: %.2f)\n", n_factors, factorScore)
- fmt.Printf("Totative Ratio: %03.1f%%\n",
- factors.TotativeRatio(n)*100.0)
- fmt.Println("2345 Rank:", factors.BasicRank(n))
- if n < 1<<32 {
- printTypeMessage(factors.Type(uint32(n)))
- // MTC(n) < n^2, so n < 2^32 ensures it fits in a uint64
- fmt.Println("Multiplication Table Complexity:",
- factors.MTC(uint64(n)))
- } else {
- fmt.Printf("Multiplication Table Complexity ≤ %.4g\n",
- float32(n)*float32(n-2))
- }
- fmt.Printf("Natural Logarithm: %.2f\n", math.Log(float64(n)))
- writeDigitMap(os.Stdout, factors.DigitMap(n))
+ factorInfo := GetFactorInfo(uint(n))
+ factorInfo.WriteTo(os.Stdout)
} else {
fmt.Println("Argument must be an integer above 1.")
}
@@ -43,16 +22,3 @@ func main() {
fmt.Println("Please provide an argument (radix to study).")
}
}
-
-func printTypeMessage(t factors.NumberType) {
- switch t {
- case factors.ColossallyAbundant:
- fmt.Println("This radix is colossally abundant!")
- case factors.Superabundant:
- fmt.Println("This radix is superabundant.")
- case factors.OrderedExponent:
- fmt.Println("This radix has ordered exponents.")
- case factors.Practical:
- fmt.Println("This radix is practical.")
- }
-}