示例#1
0
func Solve32() (solution int) {
	perms := util.LexicographicsPermutations([]int{1, 2, 3, 4, 5, 6, 7, 8, 9})
	prods := make(map[int]struct{})

	for p := range perms {
		oneFourFour := p[0] * (p[1]*1000 + p[2]*100 + p[3]*10 + p[4])
		if oneFourFour < 10000 {
			prod := p[5]*1000 + p[6]*100 + p[7]*10 + p[8]
			if oneFourFour == prod {
				prods[prod] = struct{}{}
			}
		}

		twoThreeFour := (p[0]*10 + p[1]) * (p[2]*100 + p[3]*10 + p[4])
		if twoThreeFour > 1000 && twoThreeFour < 10000 {
			prod := p[5]*1000 + p[6]*100 + p[7]*10 + p[8]
			if twoThreeFour == prod {
				prods[prod] = struct{}{}
			}
		}
	}

	for p, _ := range prods {
		solution += p
	}

	return
}
示例#2
0
func Solve24() (solution int) {
	p := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

	// This could be done faster doing in-place permutations on a single slice
	i := 0
	for p := range util.LexicographicsPermutations(p) {
		if i == 999999 {
			for _, n := range p {
				solution *= 10
				solution += n
			}
			return solution
		}
		i++
	}
	return
}