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) }