-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday18_2.go
39 lines (31 loc) · 872 Bytes
/
day18_2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package day18
import (
"fmt"
"github.com/blfuentes/AdventOfCode_2024_Go/utilities"
)
func findCorrupted(themap [][]Coord, corrupted []Coord, start, goal Coord) Coord {
result := Coord{-1, -1, Empty}
cIdx := 0
for true {
corrupted := corrupted[cIdx]
themap[corrupted.Y][corrupted.X].Kind = Corrupted
pathresult := findShortestPath(themap, start, goal)
if pathresult < 0 {
return corrupted
}
cIdx++
}
return result
}
func Executepart2() string {
var result string = ""
var fileName string = "./day18/day18.txt"
if fileContent, err := utilities.ReadFileAsLines(fileName); err == nil {
size := 70
themap, corrupted := parseContent(fileContent, size)
start, goal := Coord{0, 0, Empty}, Coord{size, size, Empty}
found := findCorrupted(themap, corrupted, start, goal)
result = fmt.Sprintf("%v,%v", found.X, found.Y)
}
return result
}