Exemple #1
0
func Euler023(limit int) int {
	abNums := []int{}

	for i := 1; i < limit; i++ {
		d := utils.Divisors(i)
		if utils.Sum(d[:len(d)-1]) > i {
			abNums = append(abNums, i)
		}
	}

	possibleSums := make(map[int]bool)

	for _, a1 := range abNums {
		for _, a2 := range abNums {
			if a1+a2 < limit {
				possibleSums[a1+a2] = true
			}
		}
	}

	sum := 0
	for i := 0; i < limit; i++ {
		if !possibleSums[i] {
			sum += i
		}
	}
	return sum
}
Exemple #2
0
func d(n int) (sum int) {
	dn := utils.Divisors(n) //Divisors returns also the number itself at the end of the slice
	// so we need to remove it later from loop
	dnl := len(dn)

	for _, v := range dn[:dnl-1] {
		sum += v
	}
	return sum
}
Exemple #3
0
func Euler012(target int) int {
	tNum, i, numDiv := 1, 1, 1
	for numDiv < target {
		i++
		tNum += i
		numDiv = len(utils.Divisors(tNum))
	}

	return tNum
}