summaryrefslogtreecommitdiff
path: root/factors
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-09-07 13:15:40 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2023-09-07 13:15:40 -0500
commit3cfb1fdcbe83c1ee4adf8e370f0922ca41c472c6 (patch)
tree2695b9decec500c1c5137b79e8fd83a95961c2a0 /factors
parent7fa8cf9666cd3427dd078bb4a5fdb9fa30c94b09 (diff)
Add ability to display specific totative digits
Instead of just saying how many totative digits there are, the new -t flag allows the user to determine the specific digits. All totatives will end in one of these digits, and all primes are either factors or totatives. This feature is not useful in comparing radices, only learning one you have already chosen. Because there can be so many totatives (p - 1 of them for primes!), this is not displayed by default. The digit map (without -f) gives this information, and beyond its range every number will have more than 8 totatives, so do not use this flag if you only want the count.
Diffstat (limited to 'factors')
-rw-r--r--factors/totative.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/factors/totative.go b/factors/totative.go
index 680cc26..abbbe89 100644
--- a/factors/totative.go
+++ b/factors/totative.go
@@ -17,3 +17,17 @@ func Totient(n uint) uint {
return num * (n / denom)
}
+
+// TotativeDigits returns a slice containing every number less than r
+// that is a totative of r (shares no factors with r).
+func TotativeDigits(r uint32) []uint32 {
+ digits := make([]uint32, Totient(uint(r)))
+ totativesFound := 0
+ for d := uint32(0); d < r; d++ {
+ if gcd(d, r) == 1 {
+ digits[totativesFound] = d
+ totativesFound++
+ }
+ }
+ return digits
+}