func main() { starttime := time.Now() total := 0 list := make([]int64, 0) for j := int64(2); j < 100; j++ { for i := int64(2); euler.IntExp(j, i) < lid && euler.IntExp(j, i) > 0; i++ { if int64(euler.DigitSum((euler.IntExp(j, i)))) == j { total++ list = append(list, euler.IntExp(j, i)) } } } list = euler.SortLInts(list) euler.ReverseLInts(list) fmt.Println(list[target-1]) fmt.Println("Elapsed time:", time.Since(starttime)) }
func test(repeat string, n, d int) (N int, S int64) { for i := 0; int64(i) < euler.Choose(int64(n), int64(d)); i++ { indices := euler.SplitSeq(d, i) for j := 0; int64(j) < euler.IntExp(10, int64(d)); j++ { insertstring := strconv.Itoa(j) for len(insertstring) < d { insertstring = "0" + insertstring } merged := "" current := 0 for index := 0; index < n; index++ { if current < d && index == indices[d-current-1] { merged += insertstring[current : current+1] current++ } else { merged += repeat } } mergedint, _ := strconv.ParseInt(merged, 10, 64) //exclude leading zeroes if mergedint > euler.IntExp(10, int64(n)-1) { if euler.IsPrime(mergedint) { //fmt.Println(mergedint) N++ S += mergedint } } } } return }
func search(length int, c chan int) { limit := 3 * length test := make([]int, length) inner := func() { //fmt.Println(test, limit) if sum(test) == prod(test) { //fmt.Println(test) limit = sum(test) } } var level func(int) level = func(lvl int) { start := 1 if lvl > 1 { start = test[lvl-2] } leftprod := int64(1) var rightprod int64 if start >= 2 && 1+length-lvl >= 13 { rightprod = infinity } else { rightprod = euler.IntExp(int64(start), int64(1+length-lvl)) } for test[lvl-1] = start; sum(test[0:lvl])+((length-lvl)*test[lvl-1]) < limit && leftprod*rightprod < int64(limit); test[lvl-1]++ { if lvl >= length { inner() } else { level(lvl + 1) } if lvl > 0 { leftprod = int64(prod(test[0 : lvl-1])) } else { leftprod = 1 } if test[lvl-1] >= 2 && 1+length-lvl >= 13 { rightprod = infinity } else { rightprod = euler.IntExp(int64(test[lvl-1]), int64(1+length-lvl)) } //fmt.Println(test[lvl-1], "to the", length-lvl+1, "is", rightprod) } } level(1) c <- limit }