Can this container hold this much liquid?
Challenge Synopsis
As you most likely know, liquids have an indefinite shape and a definite volume. As such, they always take the shape of their container. They cannot, however, expand to fill their container.
Your job today is to determine whether or not a certain amount of liquid (represented by a certain number of L
characters or numbers representing the volume of the part, as per suggestion) can fit into a container of a certain size (represented by a matrix of C
characters) with some amount of empty space (represented by space characters) within it. The container will always have C
characters all the way around the perimeter.
Your program will return a truthy/falsey value based on whether the liquid will fit into the container. It will only fit if there is an area of connected empty space (made up of spaces adjacent to one another horizontally, diagonally, or vertically) within the container for each part of the liquid that is separated from the rest (either by a space or by two newline characters).
Test Cases
LLL
L
----- True
CCCCC
C CC
C CC
CCCCC
LLL
LL
------ True
CCCCCC
C C C
C CCC
CCCCCC
L L
LLL
----- False (Not enough space)
CCCCC
CCCCC
C CC
CCCCC
LL
------ False (Spaces are not connected but liquid is)
CCCCCC
CCCC C
C CCCC
CCCCCC
L L
------ True
CCCCCC
CCCC C
C CCCC
CCCCCC
L L
------ True (There is a pocket of empty space which holds both parts of the liquid)
CCCCCC
CCC C
CCCCCC
CCCCCC
L
L
------ True (There is a pocket of empty space for each part of the liquid)
CCCCCC
CCCC C
C CCCC
CCCCCC
L L L LL
------ True
CCCCCCCCC
CCCC C C
C CCCCCCC
CCCCCC CC
CCCCCCCCC
L
L
----- True
CCCCC
CCCCC
C CC
CCCCC
Feel free to suggest test cases!
Rules
- This is code-golf, so the shortest answer in bytes wins.
- Standard loopholes are disallowed.
L\n\nL
,CCCCC\nCCCCC\nC..CC\nCCCCC
(.
represents a space,\n
represents a newline). \$\endgroup\$L
text as a list of volumes (i.e. a list of the number ofL
s in each amount)? Since parsing for spaces and double newlines seems unrelated to the core of the challenge. Also may we take theC
text as a matrix of two distinct values instead for the same reason? \$\endgroup\$L
and oneLL
with spaces of size 3 and 2 (an algorithm only filling smallest spaces first with smallest pieces of liquid still to use will yield Falsey). Maybe the same but with 2L
and oneLLL
too, to cater for the other direction. \$\endgroup\$L
to a list of integer. The second one is parsing inputC
matrix to a list of integer. And the third one is a determine question for given integer bag A and B, if there is a partition in A, when sum all integers in each partition to get a bag A', every n-th greatest number in A' is smaller (<=) than n-th greatest number in B'. \$\endgroup\$