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...)
|
||||
|
||||
12
test/main.go
12
test/main.go
@@ -3,15 +3,9 @@ package main
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// Initialize the variable before the loop
|
||||
value := 0
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
// Change its value within the loop
|
||||
value += i
|
||||
fmt.Println("Current Value:", value) // Use the variable here
|
||||
slice := []int{}
|
||||
for i := range slice {
|
||||
fmt.Println(i)
|
||||
}
|
||||
|
||||
fmt.Println("Final Value:", value) // Still accessible after the loop
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user