Ejemplo n.º 1
0
func root(n string, base int) (persistence, root int, err error) {
	i, err := digit.Sum(n, base)
	if err != nil {
		return 0, 0, err
	}
	if len(n) == 1 {
		return 0, int(i), nil
	}
	for {
		persistence++
		n := strconv.FormatInt(i, base)
		if len(n) == 1 {
			root = int(i)
			break
		}
		i, _ = digit.Sum(n, base)
	}
	return
}
func testSum(t *testing.T) {
	for _, tc := range testData {
		ds, err := digit.Sum(tc.n, tc.base)
		if err != nil {
			t.Fatal("test case", tc, err)
		}
		if ds != tc.dSum {
			t.Fatal("test case", tc, "got", ds, "expected", tc.dSum)
		}
	}
}