up till 08/01/2025
This commit is contained in:
13
10/main.go
13
10/main.go
@@ -20,33 +20,28 @@ func findTrailheads(tmap [][]int) [][]int {
|
||||
return trailheadsPositions
|
||||
}
|
||||
|
||||
func nextSteps(tmap [][]int, currentPosition []int) ([][]int, bool) {
|
||||
func nextSteps(tmap [][]int, currentPosition []int) [][]int {
|
||||
paths := [][]int{}
|
||||
found := false
|
||||
if currentPosition[0] - 1 >= 0 && tmap[currentPosition[0]-1][currentPosition[1]] == tmap[currentPosition[0]][currentPosition[1]] + 1 {
|
||||
paths = append(paths, []int{currentPosition[0]-1,currentPosition[1]})
|
||||
found = true
|
||||
}
|
||||
if currentPosition[0] + 1 < len(tmap) && tmap[currentPosition[0]+1][currentPosition[1]] == tmap[currentPosition[0]][currentPosition[1]] + 1 {
|
||||
paths = append(paths, []int{currentPosition[0]+1,currentPosition[1]})
|
||||
found = true
|
||||
}
|
||||
if currentPosition[1] + 1 < len(tmap[currentPosition[0]]) && tmap[currentPosition[0]][currentPosition[1]+1] == tmap[currentPosition[0]][currentPosition[1]] + 1 {
|
||||
paths = append(paths, []int{currentPosition[0],currentPosition[1]+1})
|
||||
found = true
|
||||
}
|
||||
if currentPosition[1] - 1 >= 0 && tmap[currentPosition[0]][currentPosition[1]-1] == tmap[currentPosition[0]][currentPosition[1]] + 1 {
|
||||
paths = append(paths, []int{currentPosition[0],currentPosition[1]-1})
|
||||
found = true
|
||||
}
|
||||
return paths, found
|
||||
return paths
|
||||
}
|
||||
|
||||
func calcPath(tmap [][]int, start []int) [][]int {
|
||||
path := [][]int{start}
|
||||
for i:=1;i<=9;i++ {
|
||||
nextStep, found := nextSteps(tmap,path[len(path)-1])
|
||||
if ! found {
|
||||
nextStep := nextSteps(tmap,)
|
||||
if len(nextStep) > 0 {
|
||||
break
|
||||
} else {
|
||||
path = append(path, nextStep...)
|
||||
|
||||
Reference in New Issue
Block a user