Exemple #1
0
func Problem_20() int {
	str, _ := helpers.BigFactorial(100, nil)
	sum := 0
	for _, c := range str {
		x, _ := strconv.Atoi(string(c))
		sum += x
	}
	fmt.Printf("The sum of the digits in 100! is %d\n", sum)
	return sum
}
Exemple #2
0
func Problem_34() int {
	cache := make(map[int]big.Int)
	total := 0
	for i := 10; i < 2540161; i++ {
		str := strconv.Itoa(i)
		sum := 0
		for _, c := range str {
			var result string
			result, cache = helpers.BigFactorial(int(c-'0'), cache)
			x, _ := strconv.Atoi(result)
			sum += x
		}
		if sum == i {
			total += i
		}
	}
	fmt.Printf("The sum of all numbers which are equal to the sum of the "+
		"factorial of their digits is %d\n", total)
	return total
}