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
|
return trailheadsPositions
|
||||||
}
|
}
|
||||||
|
|
||||||
func nextSteps(tmap [][]int, currentPosition []int) ([][]int, bool) {
|
func nextSteps(tmap [][]int, currentPosition []int) [][]int {
|
||||||
paths := [][]int{}
|
paths := [][]int{}
|
||||||
found := false
|
|
||||||
if currentPosition[0] - 1 >= 0 && tmap[currentPosition[0]-1][currentPosition[1]] == tmap[currentPosition[0]][currentPosition[1]] + 1 {
|
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]})
|
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 {
|
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]})
|
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 {
|
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})
|
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 {
|
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})
|
paths = append(paths, []int{currentPosition[0],currentPosition[1]-1})
|
||||||
found = true
|
|
||||||
}
|
}
|
||||||
return paths, found
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcPath(tmap [][]int, start []int) [][]int {
|
func calcPath(tmap [][]int, start []int) [][]int {
|
||||||
path := [][]int{start}
|
path := [][]int{start}
|
||||||
for i:=1;i<=9;i++ {
|
for i:=1;i<=9;i++ {
|
||||||
nextStep, found := nextSteps(tmap,path[len(path)-1])
|
nextStep := nextSteps(tmap,)
|
||||||
if ! found {
|
if len(nextStep) > 0 {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
path = append(path, nextStep...)
|
path = append(path, nextStep...)
|
||||||
|
|||||||
14
test/main.go
14
test/main.go
@@ -3,15 +3,9 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Initialize the variable before the loop
|
slice := []int{}
|
||||||
value := 0
|
for i := range slice {
|
||||||
|
fmt.Println(i)
|
||||||
for i := 0; i < 5; i++ {
|
}
|
||||||
// Change its value within the loop
|
|
||||||
value += i
|
|
||||||
fmt.Println("Current Value:", value) // Use the variable here
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Final Value:", value) // Still accessible after the loop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user