Пример #1
0
// Euler9 solution
func Euler9(n int) string {
	var allstrings []string

	for i := 1; i < n; i++ {
		for j := 2; j < n; j++ {
			for k := 3; k < n; k++ {
				if (i + j + k) == n {
					if goutils.IsEuclidianTriad(i, j, k) {

						var strSlice = []string{strconv.Itoa(i), strconv.Itoa(j), strconv.Itoa(k)}
						str := strings.Join(strSlice, ",")
						allstrings = append(allstrings, str)
					}
				}
			}
		}
	}
	return allstrings[len(allstrings)-1]
}
// TestIsPalindrome tests IsPalindrome
func TestIsEuclidianTriad(t *testing.T) {
	type IsEuclidianTriadTest struct {
		a    int
		b    int
		c    int
		expt bool
	}

	var tt = []IsEuclidianTriadTest{
		{1, 2, 3, true},
		{3, 2, 1, false},
	}

	for i := 0; i < len(tt); i++ {
		testIn := goutils.IsEuclidianTriad(tt[i].a, tt[i].b, tt[i].c)
		testExp := tt[i].expt

		if testIn != testExp {
			t.Error("IsEuclidianTriad test failed")
			t.Log("example " + strconv.Itoa(i+1))
		}
	}
}