Beispiel #1
0
func C041() (interface{}, error) {
	max := 0
	upperLimit := 987654321
	primes := utils.PrimesLowerThan(upperLimit)
	for _, prime := range primes {
		if utils.IsPandigital(strconv.Itoa(prime)) {
			if prime > max {
				max = prime
				// fmt.Println(prime)
			}
		}
	}
	return max, nil
}
Beispiel #2
0
func C038() (interface{}, error) {
	max := 0
	for left := 1; left < 10000; left++ {
		output := ""
		for right := 1; right < 9 && len(output) < 9; right++ {
			output += strconv.Itoa(left * right)
		}
		if len(output) == 9 && utils.IsPandigital(output) {
			nb, _ := strconv.Atoi(output)
			// fmt.Println(left, nb)
			if nb > max {
				max = nb
			}
		}
	}
	return max, nil
}
Beispiel #3
0
func C032() (interface{}, error) {
	products := map[int]bool{}
	for a := 1; a < 9000; a++ {
		for b := a + 1; b < 9000; b++ {
			product := a * b
			nbStr := fmt.Sprintf("%d%d%d", a, b, product)
			length := len(nbStr)
			if length > 9 {
				break
			}
			if length != 9 {
				continue
			}
			if utils.IsPandigital(nbStr) {
				products[product] = true
			}
		}
	}
	sum := 0
	for product := range products {
		sum += product
	}
	return sum, nil
}