Inspired by this stack of little statues that are currently on my desk at work, given to me by my colleagues from Sri Lanka when they visited The Netherlands:
This is split into two different challenges due to popular demand:
Part 1) Determine the amount of statues
Part 2) Can the statues be stacked? (this challenge)
Challenge 2:
Input:
\$statues\$: a list of multi-line strings (or character matrices), containing only the characters \n|-#
(where the #
can be another character of your own choice). You're also allowed to take it as a single multi-line string input and parse it into a list yourself.
####
## #
## ##
#### # ##
# ## ## ### ## #
# # ## ### ## # #
---- ------ -- - --
Output:
Two distinct values of your own choice indicating truthy/falsey; so yes, 1
/0
is allowed as output in languages like Java/C# .NET and such (relevant forbidden loophole). The output will be truthy if the statues can be stacked.
How can the statues be stacked?
When stacking statues, we can only stack statues with a width of the base that is \$\leq\$ the width of the top of the statue beneath it. So with the statues above, these are all possible pairs of how we could stack two statues on top of each other:
####
# ## ##
# # ## # #
---- -- - --
#### #### #### #### ##
## # ## # ## # ## # ## # #
## ## ## ## ## ## ## ## -- - -- # #
# ## # ## # ## # ## #### #### #### - -- #
## ### ## ### ## ### ## ### # ## # ## # ## ## ## -
## ### ## ### ## ### ## ### # # # # # # ## ## #
------ ------ ------ ------ ---- ---- ---- -- -- --
One possible complete stack keeping that in mind could therefore be:
#
-
#
--
##
##
--
####
# ##
# #
----
####
## #
## ##
# ##
## ###
## ###
------
So in this case the result is truthy, since the statues can be stacked.
Challenge rules:
- You can use a different consistent character other than
#
for the statue border if you want (other than- \n
). Please state which one you've used in your answer if it's different than#
. - You can use any two distinct output values to indicate truthy/falsey respectively.
- You are allowed to take the \$statues\$ input in any reasonable format. Can be a single multi-line string, a list/array/stream of multi-line strings, a list of character matrices, etc.
- You are allowed to pad the statues input with trailing spaces so it's a rectangle.
- You can assume statues are always separated by at least one space/newline from one-another, so something like
#|#|
won't be in the input. - You can assume the statues will only have a base at the bottom side, so a statue like this won't be in the input:
--
##
##
--
- You can assume all statues will only be placed on top of each other, and never next to each other if the top of a statue is large enough to hold two adjacent statues with small bases, or if it could fit on a smaller ledge. For example, these towers of statues aren't allowed when verifying if the statues can be stacked:
#
# # #
#-- - -
#### ###
---- ---
Statue on lower ledge Two statues next to each other on top of single statue
- You can assume the top and base parts of a statue are always a single piece, without any gaps. So a statue like this won't be in the input:
# #
----
But a statue like this is possible:
#
# #
----
- You can assume the base determines the width of a statue. So you won't have statues like these in the input:
#######
#####
#### ###
--- --
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Truthy test cases:
####
## #
## ##
#### # ##
# ## ## ### ## #
# # ## ### ## # #
---- ------ -- - --
__________________________________________________
##
##
##
####
# # #
---- -
__________________________________________________
# #
### #
# # #
--- -
__________________________________________________
###
###
### ## #
--- -- -
__________________________________________________
#
#### #
# ## #
### # #
##### # ###### ###
----- - ------ ---
__________________________________________________
#
# # # # # # # #
- - - - - - - -
Falsey test cases:
#
# # ##
--- --
__________________________________________________
#
# #
### ## # #
## # ## ### #####
---- -- --- -----
__________________________________________________
# #
## ### # #
-- --- - -
__________________________________________________
#
#### #
---- --