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 (this challenge)
Part 2) Can the statues be stacked?
Challenge 1:
Input:
\$statues\$: a multi-line string (or character matrix), containing only the characters \n|-#
(where the |-#
can be other characters of your own choice)
Output:
The amount of statues in the input.
Statues input example:
##|
#### |
# ##
# # |##
---- |######
| ###
|## |## #
|## - |######
# |####
The |
and -
represent the bases of the statues. So with the input above, we'll have the following statues:
####
## #
## ##
#### # ##
# ## ## ### ## #
# # ## ### ## # #
---- ------ -- - --
So the output will be 5
.
Challenge rules:
- You can use a different consistent character other than
#
,-
, and/or|
for the statue if you want (\n
are mandatory, though). Please state which one you've used in your answer if it's different than the defaults. - You are allowed to take the \$statues\$ input in any reasonable format. Can be a multi-line string, a list/array/stream of strings, a character matrix, 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 or blank line from one-another, so something like
#|#|
or#||#
won't be in the input. - You can assume the statues will only have a base at ones side, so a statue like this won't be in the input:
##|
##|
--
- It is possible that a smaller statue is within the rectangular boundaries of another oddly shaped statue. For example, this is possible:
# ##
- ##
##
####
# #
----
- Statues will never be inside of each other, though. So something like this won't be in the input:
#####
## #
# # #
# ## ##
# -- ##
# #
## #
-------
- 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:
##|
#### |
# ##
# # |##
---- |######
| ###
|## |## #
|## - |######
# |####
Output: 5
__________________________________________________
# ##
- ##
##
####
# #
----
Output: 2
__________________________________________________
#
|### #
| # #
|#### -
Output: 2
__________________________________________________
--- ##|
### ##|
###
### |#
Output: 3
__________________________________________________
#### #####|
# ##
### |# |#
##### |# |##
----- |# |#
|#
|#
|#
Output: 4
__________________________________________________
|# |# |# |# |# #| #| #|
Output: 8
__________________________________________________
|##
| ##
|# --
Output: 2
__________________________________________________
|##
---- |####
# ##
### |#
|# ###|
|# #|
|# ##|
|#
Output: 4
__________________________________________________
- |##
# #
#| ###
#| ---
Output: 4
__________________________________________________
#
####
----
--
#
Output: 2
__________________________________________________
##
##
--
--
##
##
Output: 2
_
instead of-
. This does look better, but it is not intended, right? \$\endgroup\$