Shikaku is a 2D puzzle. The basic rundown of it is that a rectangular grid has some numbers in it, and you want to partition the grid into rectangular components such that each component contains exactly one number which is the number of grid squares in that component.
This challenge involves a 1D simplification of this: it is a line of N squares with K numbers \$\{a_1, a_2, \cdots, a_K\}\$, and a solution would be a division of the line into K partitions such that each partition contains \$a_i\$ squares. However, in this simplification, not all squares need to be used.
Challenge
Given a list of N numbers (where 0 is an empty square), determine if a valid solution to that problem exists.
Truthy Cases
(_ is a blank; it will be given as 0 in the input. you may not take the input as an index:element mapping)
_ _ 3 _ _ 5 _ _ 3 _ _
([ ] [ ] [ ])
2 _ _ _ _ 6 _ _ _ 4 _ _
([ ] [ ] [ ])
_ 5 _ _ _ 3 _ _ _ _ _ 4
([ ] [ ] [ ])
_ _ 2 _ _ _ _ 4 _ _
( [ ] [ ])
( [ ] [ ] ) just to give 2 examples
Falsy Cases
_ _ 2 _ 4 _
_ 3 _ _ 5 _ _ 3 _
_ _ 5 _ _ _ 3
_ 2 _ 2 _ 2 _ 3
Rules and Specifications
Input can be taken as any convenient way to take a list of numbers. You can input it as a string with _
for blanks as well; etc. Any reasonable method; however, you may not change the general structure of the input as a list.
Output is a true/false value. Any truthy/falsy value is acceptable. The true/false value does not have to be consistent across cases, but your program must give the same exact answer for the same test case every run, and please specify how truthy/falsy is distinguished if it's not conventional. For example, you can output 1 for a true case and 2 for another, and 0 for false cases, but the first case must always yield 1 every time, and the second must give 2 every time.
To prevent a loophole brought up thanks to @xnor, your output must be successful / failed completion as a result, numbers, booleans, or other similar "primitive-like" datatypes (basically, you cannot submit the identity function and say that the Truthy/Falsy sets are divided by this problem's specifications).
- Standard loopholes are forbidden.
- This is code-golf, therefore the shortest answer in each language wins. No answer will be accepted.
_
? \$\endgroup\$