aoc2015/day02/day02.go
Stefan Harmuth c026df5d0a day02
2020-12-21 21:48:52 +01:00

62 lines
977 B
Go

package day02
import (
"aoc2015/aoclib"
"strconv"
"strings"
)
func Part1(puzzle aoclib.Puzzle) 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 aoclib.Puzzle) 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
}