aoc2023/day-18/two.go

27 lines
639 B
Go
Raw Permalink Normal View History

2023-12-22 21:57:00 +00:00
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)
2023-12-22 21:57:00 +00:00
}