main
Jason Staten 9 months ago
parent 75634e210c
commit 9e586eca69

@ -15,9 +15,9 @@ func MaxValue(capacity uint, books []Book) uint {
return 0
}
book := books[0]
withBook := book.Value + MaxValue(capacity-book.Weight, books[1:])
withoutBook := MaxValue(capacity, books[1:])
book, rest := books[0], books[1:]
withBook := book.Value + MaxValue(capacity-book.Weight, rest)
withoutBook := MaxValue(capacity, rest)
if book.Weight > capacity {
return withoutBook
}

@ -14,7 +14,9 @@ func TestDefaultsZero(t *testing.T) {
}
func TestFitsOne(t *testing.T) {
result := ks.MaxValue(1, []ks.Book{{Weight: 1, Value: 2}})
result := ks.MaxValue(1, []ks.Book{
{Weight: 1, Value: 2},
})
be.Equal(t, 2, result)
}

Loading…
Cancel
Save