62 lines
972 B
Go
62 lines
972 B
Go
package day02
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
"tools"
|
|
)
|
|
|
|
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
|
sqm := 0
|
|
for _, line := range puzzle.GetInputArray() {
|
|
dim := strings.Split(line, "x")
|
|
l, _ := strconv.Atoi(dim[0])
|
|
w, _ := strconv.Atoi(dim[1])
|
|
h, _ := strconv.Atoi(dim[2])
|
|
|
|
sqm += 2*l*w + 2*w*h + 2*h*l
|
|
if l <= w {
|
|
if w <= h {
|
|
sqm += l * w
|
|
} else {
|
|
sqm += l * h
|
|
}
|
|
} else {
|
|
if l <= h {
|
|
sqm += w * l
|
|
} else {
|
|
sqm += w * h
|
|
}
|
|
}
|
|
}
|
|
|
|
return sqm
|
|
}
|
|
|
|
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
|
length := 0
|
|
for _, line := range puzzle.GetInputArray() {
|
|
dim := strings.Split(line, "x")
|
|
l, _ := strconv.Atoi(dim[0])
|
|
w, _ := strconv.Atoi(dim[1])
|
|
h, _ := strconv.Atoi(dim[2])
|
|
|
|
length += l * w * h
|
|
if l <= w {
|
|
if w <= h {
|
|
length += 2*l + 2*w
|
|
} else {
|
|
length += 2*l + 2*h
|
|
}
|
|
} else {
|
|
if l <= h {
|
|
length += 2*w + 2*l
|
|
} else {
|
|
length += 2*w + 2*h
|
|
}
|
|
}
|
|
}
|
|
|
|
return length
|
|
}
|