summaryrefslogtreecommitdiff
path: root/factors
diff options
context:
space:
mode:
Diffstat (limited to 'factors')
-rw-r--r--factors/factors_test.go16
-rw-r--r--factors/totative.go14
2 files changed, 14 insertions, 16 deletions
diff --git a/factors/factors_test.go b/factors/factors_test.go
index af91e70..745fd2c 100644
--- a/factors/factors_test.go
+++ b/factors/factors_test.go
@@ -67,17 +67,25 @@ var totativeRatioCases = map[uint]float64{
30: 4.0 / 15.0, 60: 4.0 / 15.0, 120: 4.0 / 15.0,
}
+func totativeRatio(n uint) float64 {
+ if n == 0 {
+ panic("0 has no totative ratio!")
+ }
+
+ return float64(Totient(n)) / float64(n)
+}
+
func TestTotativeRatio(t *testing.T) {
- tableTest(t, TotativeRatio, totativeRatioCases, stdEquals, "TotativeRatio")
+ tableTest(t, totativeRatio, totativeRatioCases, stdEquals, "TotativeRatio")
}
-var totativeCountCases = map[uint]uint{
- 1: 1, 2: 1, 3: 2, 4: 2, 6: 2, 7: 6, 8: 4, 12: 4,
+var totientCases = map[uint]uint{
+ 0: 0, 1: 1, 2: 1, 3: 2, 4: 2, 6: 2, 7: 6, 8: 4, 12: 4,
14: 6, 15: 8, 30: 8, 60: 16, 120: 32,
}
func TestTotativeCount(t *testing.T) {
- tableTest(t, TotativeCount, totativeCountCases, stdEquals, "TotativeCount")
+ tableTest(t, Totient, totientCases, stdEquals, "Totient")
}
var factorScoreCases = map[uint]float64{
diff --git a/factors/totative.go b/factors/totative.go
index 7a4bebe..680cc26 100644
--- a/factors/totative.go
+++ b/factors/totative.go
@@ -1,18 +1,8 @@
package factors
-// TotativeRatio calculates the fraction of numbers that
+// Totient calculates the number of numbers less than n that
// are totatives of n (share no factors with n)
-func TotativeRatio(n uint) float64 {
- if n == 0 {
- panic("0 has no totative ratio!")
- }
-
- return float64(TotativeCount(n)) / float64(n)
-}
-
-// TotativeCount calculates the number of numbers less than n that
-// are totatives of n (share no factors with n)
-func TotativeCount(n uint) uint {
+func Totient(n uint) uint {
if n == 0 {
return 0
}