aoc2023/day-18/two.go
2023-12-24 10:50:41 +00:00

27 lines
639 B
Go

package main
import (
"strings"
)
func fromHex(imager *imager, lines []string) {
for _, line := range lines {
direction, count := func() (string, int) {
var dirs = []string{"R", "D", "L", "U"}
m := getParams(r, line)
code := strings.TrimLeft(m["colour"], "#")
return dirs[mustConv(string(code[len(code)-1]))], mustConvHex(code[:len(code)-1])
}()
imager.add(direction, count)
}
}
// two returns the area of the polygon described by imager.space
// it uses the hex codes to define points
func two(lines []string) int {
imager := newImager()
buildImage(fromHex, imager, lines)
return calculateArea(imager.space)
}