Challenge:
Given an ASCII art of a (possibly leaky) bowl consisting of a random distinct non-whitespace and non-~
character, fill it completely with ~
characters. If the bowl is leaky, fill the bottom row below the bowl and a stream of liquid emerging from that, with the intended amount of ~
if the bowl would not have been leaky.
For example:
Regular bowl:
Input | Output |
---|---|
|
|
Leaky bowl:
Input | Output |
---|---|
|
|
If there wouldn't have been a leak, it could have contained eight ~
. Instead, the bottom row including leak position is now filled with five ~
, and the remaining three ~
are below the leak.
(Imagine the bowl standing on a table, so the five ~
at the bottom row of the bowl are on the table, and the ~
vertically below the leak are dripping off the table.)
Challenge rules:
- The potential leak is guaranteed to be at the bottom row, and there will never be any gaps at the sides of a bowl.
- The potential leak is guaranteed to be a single character gap.
- The character used for the bowl can be any printable ASCII character, except for the
~
and whitespaces. - The bowl can be in an irregular shape (see some of the test cases).
- The top ridges of the bowl are guaranteed to be on the same top row, and there will only be two top ridges.
- If the bottom row contains more space characters than inside the leaky bowl (see the third leaky bowl test case below), we still fill the entire bottom row of the output regardless, but there won't be any additional
~
below it. - For the sake of this challenge, there won't be any smaller inner bowls (e.g. no doughnut-shaped bowls if we'd imagine it as 3D). So every space in the bowl will always flow towards the leak. (See the fourth leaky bowl test case below, which doesn't have
#~# #
as its second line.) - There also won't be any enclosed blobs at the sides (or inside) of a bowl, not any 'stalagmites' nor 'stalactites'.
- The bottom of the bowl won't have a path traveling up and back down.
- I/O is flexible. Could be a multi-line string; a list of lines; a character matrix; etc.
- You're allowed to pad the input with trailing spaces to make the input a rectangle.
- You're allowed to have leading/trailing whitespaces and/or newlines in the output, as long as the expected result is somewhere on the screen.
Here some examples of invalid bowls based on the rules. Your program can have unspecified behavior for any of the invalid bowls. If you have a question about a certain bowl-shape, feel free to ask in the comments.
General rules:
- This is code-golf, so the 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 (e.g. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases
Regular bowls:
Inputs | Outputs |
---|---|
|
|
|
|
|
|
|
|
|
|
Leaky bowls:
Inputs | Outputs |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|