24: lexicographic permutations

This commit is contained in:
VicRen
2020-10-23 13:46:05 +08:00
parent acfe8ce353
commit 86ae6bb4a7
3 changed files with 157 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"strconv"
"time"
)
var src = "73167176531330624919225119674426574742355349194934" +
@@ -36,8 +37,10 @@ func main() {
nextSrc = append(nextSrc, i)
src = src[1:]
}
t := time.Now()
var next []int
var out int
var outS []int
for {
next, nextSrc = FetchNextAdjacent(13, nextSrc)
if len(next) == 0 {
@@ -50,10 +53,12 @@ func main() {
}
if product > out {
out = product
outS = next
}
}
fmt.Println("the largest product is", out)
fmt.Println("time:", time.Since(t))
fmt.Println("the largest product is", out, outS)
}
func FetchNextAdjacent(n int, src []int) ([]int, []int) {