mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
27 lines
639 B
Go
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)
|
|
}
|