Beispiel #1
0
func Euler24() string {
	str := "0123456789"
	bytes := []byte(str)
	for i := 1; i < 1000000; i++ {
		arithmetics.Permute(bytes)
	}
	return fmt.Sprint(string(bytes))
}
Beispiel #2
0
func Euler43() string {
	sum := uint64(0)
	pand := []byte("1023456789")
	for arithmetics.Permute(pand) {
		hasProperty := true
		for i, prime := range smallprimes {
			num, _ := strconv.Atoui64(string(pand[1+i : 4+i]))
			if num%prime != 0 {
				hasProperty = false
				break
			}
		}
		if hasProperty {
			num, _ := strconv.Atoui64(string(pand))
			sum += num
		}
	}
	return fmt.Sprint(sum)
}
Beispiel #3
0
func Euler41() string {
	maxPandigital := "123456789"
	max := 0
	for i := len(maxPandigital); i > 3; i-- {
		pandigital := []byte(maxPandigital[0:i])
		for arithmetics.Permute(pandigital) {
			number, _ := strconv.Atoi(string(pandigital))
			if big.ProbablyPrime(big.NewInt(int64(number)), 1) {
				if number > max {
					max = number
				}
			}
		}
		if max != 0 {
			return fmt.Sprint(max)
		}
	}
	return "Error not prime found"
}