Ejemplo n.º 1
0
func isReverseTruncatablePrime(num string) bool {
	length := len(num)
	for i := 0; i < length-1; i++ {
		x, _ := strconv.Atoi(num[length-1-i:])
		if !primes.IsPrime(x) {
			fmt.Println(" X Not Reverse Truncatable Prime becuase", x, "is not prime")
			return false
		}
	}
	fmt.Print(" +Reverse Truncatable Prime")
	return true
}
Ejemplo n.º 2
0
func main() {

	result := 2
	for i := []int{1, 2, 3}; len(i) < 10; i = append(i, i[len(i)-1]+1) {
		fmt.Println(i)
		pandigital := operations.Permutations(i)
		for _, x := range pandigital {
			if primes.IsPrime(x) && x > result {
				fmt.Println(x)
				result = x
			}
		}
	}

}
Ejemplo n.º 3
0
func main() {
	numbers := []string{"1", "3", "7", "9"}
	results := make([]int, 0)

	current := map[string]int{"2": 0, "3": 0, "5": 0, "7": 0}

	for {
		next := make(map[string]int)
		for k, _ := range current {
			for _, n := range numbers {
				newNum, _ := strconv.Atoi(k + n)
				fmt.Print("Checking ", newNum)
				if primes.IsPrime(newNum) {
					fmt.Print(" +Prime")
					next[k+n] = 1
					if isReverseTruncatablePrime(k + n) {
						fmt.Println(" !!!FOUND:", newNum, "!!!")
						results = append(results, newNum)
					}
				} else {
					fmt.Println(" X Not Prime")
				}

			}
		}
		fmt.Println(next)
		fmt.Println(results)
		if len(next) == 0 {
			break
		} else {
			current = next
		}
	}
	fmt.Println(results)
	sum := 0
	for _, x := range results {
		sum += x
	}
	fmt.Println(sum)
}