2023-12-22 21:57:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
|
|
|
var r = regexp.MustCompile(`(?P<direction>[A-Z]) (?P<count>[0-9]+) \((?P<colour>.*)\)`)
|
|
|
|
|
|
|
|
func fromRegex(imager *imager, lines []string) {
|
|
|
|
for _, line := range lines {
|
|
|
|
direction, count := func() (string, int) {
|
|
|
|
x := getParams(r, line)
|
|
|
|
return x["direction"], mustConv(x["count"])
|
|
|
|
}()
|
|
|
|
imager.add(direction, count)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildImage(withParser func(imager *imager, lines []string), imager *imager, lines []string) {
|
|
|
|
withParser(imager, lines)
|
|
|
|
}
|
|
|
|
|
|
|
|
// one returns the area of the polygon described by imager.space
|
|
|
|
func one(lines []string) int {
|
|
|
|
imager := newImager()
|
|
|
|
buildImage(fromRegex, imager, lines)
|
|
|
|
|
2023-12-24 10:50:41 +00:00
|
|
|
return calculateArea(imager.space)
|
2023-12-22 21:57:00 +00:00
|
|
|
}
|