// TestIsPalindrome tests IsPalindrome func TestIsPalindrome(t *testing.T) { var tt = []goutils.TTSB{ {"me", false}, {"bob", true}, {"90", false}, {"909", true}, } for i := 0; i < len(tt); i++ { testIn := goutils.IsPalindrome(tt[i].Test) testExp := tt[i].Expt if testIn != testExp { t.Error("IsPalindrome test failed") } } }
// Euler4 solution func Euler4(p int) string { p-- upperL := int(math.Pow(10, float64(p))) - 1 p-- lowerL := int(math.Pow(10, float64(p))) for j := upperL; j > lowerL; j-- { for k := upperL; k > lowerL; k-- { prod := strconv.Itoa(j * k) if goutils.IsPalindrome(prod) { str := []string{strconv.Itoa(j), ",", strconv.Itoa(k)} nums := strings.Join(str, "") return nums } } } return "" }