diff options
| author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-09-12 20:01:33 -0500 |
|---|---|---|
| committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-09-12 20:01:33 -0500 |
| commit | 345f6bae7b005cdd386833aa496aa71ca11c7b97 (patch) | |
| tree | 023e583e692b5dfff9ccfc0e290fc1fdb10f62e5 | |
| parent | d6bb5352f93f2260f4a37ccd7c71bd08c4d03340 (diff) | |
Add option to show digit map only
This is intended to allow users to easily view the digit maps of many
different radices at once by running the program multiple times.
| -rw-r--r-- | args.go | 5 | ||||
| -rw-r--r-- | radix_info.go | 14 |
2 files changed, 17 insertions, 2 deletions
@@ -16,6 +16,7 @@ type args struct { FullMap bool ExactMTCLarge bool TotativeDigits bool + DigitMapOnly bool // If true, exit the program immediately after parsing args. Exit bool } @@ -23,6 +24,8 @@ type args struct { func parseArgs() (args, error) { var a args flag.BoolVar(&a.Compact, "c", false, "Compact the output display") + flag.BoolVar(&a.DigitMapOnly, "d", false, + "Show only the digit map; incompatible with -m and -t") flag.BoolVar(&a.FullMap, "f", false, fmt.Sprintf("Show full digit map (up to %d) for every radix", maxSmallRadix)) @@ -45,6 +48,8 @@ func parseArgs() (args, error) { return args{Exit: true}, nil } else if a.Compact && a.TotativeDigits { return args{}, errors.New("You cannot use both -t and -c at the same time.") + } else if a.DigitMapOnly && (a.TotativeDigits || a.ExactMTCLarge) { + return args{}, errors.New("You cannot use both -d and -t or -m at the same time.") } else { if flag.NArg() == 1 { if radix, err := strconv.ParseUint(flag.Arg(0), 0, 0); err == nil { diff --git a/radix_info.go b/radix_info.go index f495905..befc25d 100644 --- a/radix_info.go +++ b/radix_info.go @@ -14,9 +14,19 @@ func main() { if err == nil { factorInfo := getFactorInfo(args) if args.Compact { - factorInfo.writeToCompact(os.Stdout) + if args.DigitMapOnly { + fmt.Printf("Radix %02d ", args.Radix) + writeDigitMapCompact(os.Stdout, factorInfo.DigitMap) + } else { + factorInfo.writeToCompact(os.Stdout) + } } else { - factorInfo.writeTo(os.Stdout) + if args.DigitMapOnly { + fmt.Printf("Radix %d Digit Map:\n", args.Radix) + writeDigitMap(os.Stdout, factorInfo.DigitMap) + } else { + factorInfo.writeTo(os.Stdout) + } } } else { fmt.Fprintln(os.Stderr, err) |
