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)
|
|
|
|
|
2023-12-24 10:50:41 +00:00
|
|
|
return calculateArea(imager.space)
|
2023-12-22 21:57:00 +00:00
|
|
|
}
|