package day09 import ( "fmt" "log" ) func Run() { res, err := calc1("data/day09.dat") if err != nil { log.Fatal(err) } fmt.Printf("Part 1: %d\n", res) } func calc1(path string) (int, error) { heightMap, err := readFile(path) if err != nil { return 0, err } var risk int // assume rectangle map form lenRow := len(heightMap[0]) lenColumn := len(heightMap) for i, row := range heightMap { for j, point := range row { if ((i-1 >= 0 && point < heightMap[i-1][j]) || i == 0) && ((i+1 < lenColumn && point < heightMap[i+1][j]) || i == lenColumn-1) && ((j-1 >= 0 && point < heightMap[i][j-1]) || j == 0) && ((j+1 < lenRow && point < heightMap[i][j+1]) || j == lenRow-1) { risk += point + 1 } } } return risk, nil }