Golang beginner - DFS + DP
Intuition\nThis is a typical resursive DFS search + DP problem\n\nMyy golang is not good, so just see the idea of solving\n\n# Code\n\n\ntype State struct {\n\t
# Intuition\nThis is a typical resursive DFS search + DP problem\n\nMyy golang is not good, so just see the idea of solving\n\n# Code\n```\n\ntype State struct {\n\tstate    []bool\n\tcurRound int\n}\n\ntype Result struct {\n\tearliest int\n\tlatest   int\n}\n\nvar visited map[string]Result\n\nfunc (s State) ToString() string {\n\treturn fmt.Sprintf("%v", s.state)\n}\n\nfunc (r *Result) Merge(other Result) {\n\tif other.earliest < r.earliest {\n\t\tr.earliest = other.earliest\n\t}\n\tif other.latest > r.latest {\n\t\tr.latest = other.latest\n\t}\n}\n\nfunc SolveInternal(state State) (result Result) {\n\tif r, ok := visited[state.ToString()]; ok {\n\t\treturn r\n\t}\n\n\tstate.curRound++\n\n\tfmt.Println("SolveInternal", state)\n\n\tmakingQueue := [][]int{\n\t\tmake([]int, 0),\n\t}\n\tcompletedQueue := make([]State, 0)\n\toldState := state.state\n\n\tfor len(makingQueue) > 0 {\n\t\tmakingState := makingQueue[0]\n\t\tmakingQueue = makingQueue[1:]\n\n\t\tcurIndex := len(makingState)\n\n\t\t//fmt.Println("Examining ", makingState, "curIndex", curIndex)\n\n\t\tif curIndex == len(oldState)/2 {\n\t\t\tif len(oldState)%2 == 1 {\n\t\t\t\tmakingState = append(makingState, curIndex)\n\t\t\t}\n\n\t\t\tsort.Ints(makingState)\n\t\t\tcompletedState := State{\n\t\t\t\tstate:    make([]bool, len(makingState)),\n\t\t\t\tcurRound: state.curRound,\n\t\t\t}\n\t\t\tfor i := range makingState {\n\t\t\t\tcompletedState.state[i] = oldState[makingState[i]]\n\t\t\t}\n\t\t\tcompletedQueue = append(completedQueue, completedState)\n\t\t} else {\n\t\t\toppIndex := len(oldState) - curIndex - 1\n\n\t\t\tif oldState[curIndex] && oldState[oppIndex] {\n\t\t\t\tfmt.Println("Found terminal condition at ", state)\n\t\t\t\treturn Result{earliest: state.curRound, latest: state.curRound}\n\t\t\t}\n\t\t\tif !oldState[curIndex] {\n\t\t\t\t//fmt.Println("- adding", oppIndex, "to", makingState, "as curIndex", curIndex, "is not true")\n\t\t\t\tmakingQueue = append(makingQueue, append(makingState, oppIndex))\n\t\t\t}\n\t\t\tif !oldState[oppIndex] {\n\t\t\t\t//fmt.Println("- adding", curIndex, "to", makingState, "as curIndex", oppIndex, "is not true")\n\t\t\t\tcopiedState := make([]int, len(makingState))\n\t\t\t\tcopy(copiedState, makingState)\n\t\t\t\tmakingQueue = append(makingQueue, append(copiedState, curIndex))\n\t\t\t}\n\t\t}\n\t}\n\n\tresult = Result{earliest: math.MaxInt, latest: math.MinInt}\n\n\tfor _, newState := range completedQueue {\n\t\tnewState.curRound = state.curRound\n\n\t\toneResult := SolveInternal(newState)\n\t\tresult.Merge(oneResult)\n\t}\n\n\tvisited[state.ToString()] = result\n\treturn\n}\n\nfunc earliestAndLatest(n int, firstPlayer int, secondPlayer int) []int {\n\n\tvisited = make(map[string]Result)\n\n\tfmt.Println("Started to solve", n, firstPlayer, secondPlayer)\n\n\tstate := State{\n\t\tstate:    make([]bool, n),\n\t\tcurRound: 0,\n\t}\n\n\tfor i := 0; i < n; i++ {\n\t\tstate.state[i] = (i+1) == firstPlayer || (i+1) == secondPlayer\n\t}\n\n\tresult := SolveInternal(state)\n\n\tfmt.Println("Finished", result)\n\n\treturn []int{result.earliest, result.latest}\n}\n```
['Go']