Compare commits
2 Commits
2d6c89d7c9
...
1f5b8247a9
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f5b8247a9 | |||
| 950eec898e |
@@ -29,5 +29,20 @@ func PartOne(data []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func PartTwo(data []string) int {
|
func PartTwo(data []string) int {
|
||||||
return 0
|
total := 0
|
||||||
|
for _, line := range data {
|
||||||
|
parts := strings.Split(line, "x")
|
||||||
|
length, _ := strconv.Atoi(parts[0])
|
||||||
|
width, _ := strconv.Atoi(parts[1])
|
||||||
|
height, _ := strconv.Atoi(parts[2])
|
||||||
|
|
||||||
|
smallest := min(length, width, height)
|
||||||
|
middle := length + width + height - smallest - max(length, width, height)
|
||||||
|
|
||||||
|
perimeter := 2 * (smallest + middle)
|
||||||
|
volume := length * width * height
|
||||||
|
|
||||||
|
total += perimeter + volume
|
||||||
|
}
|
||||||
|
return total
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,3 +21,23 @@ func TestPartOne(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPartTwo(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
expected int
|
||||||
|
}{
|
||||||
|
{"2x3x4", "2x3x4", 34},
|
||||||
|
{"1x1x10", "1x1x10", 14},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got := PartTwo([]string{tt.input})
|
||||||
|
if got != tt.expected {
|
||||||
|
t.Errorf("PartTwo(%q) = %d, want %d", tt.input, got, tt.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user