Пример #1
0
func Euler042() int {
	ns, err := ioutil.ReadFile("../resources/p042_words.txt")
	if err != nil {
		panic("could not read words file")
	}

	words := strings.Split(strings.Trim(string(ns), "\""), "\",\"")

	n := 0
	for _, w := range words {
		if utils.IsTriangular(utils.Score(w)) {
			n++
		}
	}
	return n
}
Пример #2
0
func Euler022() int {

	ns, err := ioutil.ReadFile("../resources/p022_names.txt")
	if err != nil {
		panic("could not read names file")
	}

	names := strings.Split(strings.Trim(string(ns), "\""), "\",\"")
	sort.Strings(names)
	total := 0
	for i, v := range names {
		total += utils.Score(v) * (i + 1)
	}

	return total
}