package one import ( "bytes" log "github.com/sirupsen/logrus" ) func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) graph, err := parseLines(r) if err != nil { return 0, err } var totalCost int totalAreaVisited := make(map[point]struct{}) for y := range graph.data { for x := range graph.data[y] { start := newPoint(x, y) if graph.isOutOfBounds(start) { continue } _, ok := totalAreaVisited[start] if ok { continue } totalAreaVisited[start] = struct{}{} path := explore(start, graph) log.Debugf("\n%s\n", graph.debug(path.visited)) totalCost += len(path.visited) * path.perimeter for point := range path.visited { totalAreaVisited[point] = struct{}{} } } } return totalCost, nil }