diff --git a/10/main.go b/10/main.go index 703209b..e49bf4d 100644 --- a/10/main.go +++ b/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...) diff --git a/test/main.go b/test/main.go index 883b0b7..b60a4d6 100644 --- a/test/main.go +++ b/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 - } - - fmt.Println("Final Value:", value) // Still accessible after the loop + slice := []int{} + for i := range slice { + fmt.Println(i) + } }