diff options
| author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-08-30 14:27:19 -0500 |
|---|---|---|
| committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-08-30 14:29:52 -0500 |
| commit | 45d7d682c7e9676802fb21e74e47a3c7cca30e19 (patch) | |
| tree | 5895cf21c4a79931f0518f161ab9bd705e22426d /print_digit_map.go | |
| parent | 778220b2e3ce662e733727fb9a560fcfe85c19eb (diff) | |
Print digit map to stdout
Diffstat (limited to 'print_digit_map.go')
| -rw-r--r-- | print_digit_map.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/print_digit_map.go b/print_digit_map.go new file mode 100644 index 0000000..356ca37 --- /dev/null +++ b/print_digit_map.go @@ -0,0 +1,37 @@ +package main + +import ( + "aphopkins/radix_info/factors" + "fmt" + "io" + "strconv" + "strings" +) + +func writeDigitMap(w io.Writer, digitMap []factors.DigitType) { + if len(digitMap) <= 2 { + panic("Radices cannot be less than 2!") + } else if len(digitMap) <= 36 { + writeDigitMapSmall(w, digitMap) + } +} + +// Prints a digit map suitable for small bases (≤36). +func writeDigitMapSmall(w io.Writer, digitMap []factors.DigitType) { + radix := uint(len(digitMap)) + digitsString := strings.Builder{} + digitsString.Grow(int(3*radix + 6)) + digitsString.WriteString("Digit:") + typesString := strings.Builder{} + typesString.WriteString("Class:") + for digit, digitType := range digitMap { + digitString := fmt.Sprintf("%2s", strings.ToUpper( + strconv.FormatUint(uint64(digit), int(radix)))) + typeString := digitType.String() + fmt.Fprintf(&digitsString, " %s", digitString) + fmt.Fprintf(&typesString, " %s", typeString) + } + + fmt.Fprintln(w, digitsString.String()) + fmt.Fprintln(w, typesString.String()) +} |
