Beispiel #1
0
func Run() {
	base := []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}

	for i := 1; i < 1000000; i++ {
		done := euler.NextPermutation(ByteSlice(base))
		if done {
			panic("Done early")
		}
	}

	fmt.Printf("%s\n", base)
}
Beispiel #2
0
// Compute all of the digit permutations of the number.
func allPermutations(base int) (perms []int) {
	perms = make([]int, 1)
	perms[0] = base

	work := euler.DigitsOf(base)
	iwork := sort.IntSlice(work)
	for !euler.NextPermutation(iwork) {
		perms = append(perms, euler.OfDigits(work))
	}

	return
}
Beispiel #3
0
func Run() {
	base := []intBase{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

	sum := intBase(0)
	for {
		done := euler.NextPermutation(intBaseSlice(base))
		if done {
			break
		}

		if check(base) {
			sum += numberOf(base)
		}
	}

	fmt.Printf("%d\n", sum)
}
Beispiel #4
0
func Run() {
	base := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}

	sum := 0
	seen := make(map[int]bool)

	for {
		done := euler.NextPermutation(sort.IntSlice(base))
		if done {
			break
		}

		possible, product := isProduct(base)
		if possible && !seen[product] {
			sum += product
			seen[product] = true
		}
	}

	fmt.Printf("%d\n", sum)
}