[Question]
  [
## 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 |
| --- | --- |
| 
```
00     00 00   00   000 0  
```
 | 
```
00     00 00   00 ~~000~0~~     ~        ~        ~   
```
 |
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.**](https://pastebin.com/20NzwGyp) 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](/questions/tagged/code-golf "show questions tagged '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](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/2422#2422) for your answer with [default I/O rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/), so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
* [Default Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* If possible, please add a link with a test for your code (e.g. [TIO](https://tio.run/#)).
* Also, adding an explanation for your answer is highly recommended.
## Test cases
*Regular bowls:*
| Inputs | Outputs |
| --- | --- |
| 
```
#      # #    #   ####  
```
 | 
```
#~~~~~~# #~~~~#   ####  
```
 |
| 
```
!!!        !!   !!      !      !!!   !         !!!! 
```
 | 
```
!!!~~~~~~~~!!   !!~~~~~~!      !!!~~~!         !!!! 
```
 |
| 
```
4   44 4 444444
```
 | 
```
4~~~44~4~444444
```
 |
| 
```
  B B   B   B B     BB     B B   B   BBB  
```
 | 
```
  B~B   B~~~B B~~~~~BB~~~~~B B~~~B   BBB  
```
 |
| 
```
sss  sss  s  s     s s  ssssssssss
```
 | 
```
sss~~sss  s~~s     s~s  ssssssssss
```
 |
*Leaky bowls:*
| Inputs | Outputs |
| --- | --- |
| 
```
00     00 00   00   000 0  
```
 | 
```
00     00 00   00 ~~000~0~~     ~        ~        ~   
```
 |
| 
```
^^^        ^   ^^      ^     ^^^   ^        ^ ^ 
```
 | 
```
^^^        ^   ^^      ^     ^^^   ^~~~~~~~~^~^~         ~           ~           ~           ~           ~           ~           ~  
```
 |
| 
```
@@@ @@@  @ @  
```
 | 
```
@@@ @@@~~@~@~~
```
 |
| 
```
#   ## # #### #
```
 | 
```
#   ## # ####~#   ~    ~    ~    ~ 
```
 |
| 
```
xx xxx   xx   x xx  
```
 | 
```
xx xxx   xx   x~xx~~   ~    ~    ~    ~ 
```
 |
| 
```
2 22 2
```
 | 
```
2 22~2
```
 |
 
  
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 145 bytes [SBCS](https://github.com/abrudz/SBCS)
A dfn taking a character matrix.
```
{h w←⍴m←' '=⍵
i←{∪⍵,(⌷∘(0@h⊢m)¨n)/n←⍵~⍨,(⌽q)(-q)q∘.+⍵}⍣≡⊂q+⊃⍸m⍷⍨q←0 1
b←h⌷m
×x←⊃⍸b∧i∊⍨(h-1),¨⍳w:'~'@((h,¨⍸b),x,⍨¨h+⍳d)⊢⍵↑⍨h+d←0⌈(≢i)-+/b
'~'@i⊢⍵}
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=JY49DoJAEIV7TkHHbgDB1sSEs2xMXApItsLESKGJWQibaKWtWkhskWhjgzd5J3EWqzc/35s3S@wPa@kWJDDPjMRzvTlM76R2A/2gOmBoXtBnFicS9TXjQ5vzKB89fQnTWuCjOAsVV8RNfJpvYG6oLqi3yke9g3lnMC@CFflid@oIUkmHM@d7WtlbIySg7yl0TSCT4ZQHQwvTFTOv9BLG5Ni@BQ9WARFDKymqW3D6iiKxP9JQ@gubgEYzVNeUh34kHGtP/9TmBw&f=XVE7DsIwDN17ild1yMJQ2vCdqs5MiLkSQ8UAEwWprAwMlSpxBiRuwIlyEvxJWoQb5zn2s904u7q5wD2ecN1r4vq36@6HKDLb@nA97c9rE@2YkGPp@o9JIJIgUSAlATzLYpozLY5jeBErHAOoEyOHHEOjGVew5LaWCloRH5xjwUGgpA9eS6lRehgD7Bn/K@XEpmkA2QhkQU31DGIis6n3x9t4@xWnp6nQCcTyG51@G2XMrKoqXI6NcFLQ4A@hCumZ3q8oCrCCAH@D0ZnzC/Dgk6GvBNsWLSmgm8BQWl4mQ0bLfAE&i=AwA&r=tryapl&l=apl-dyalog&m=tradfn&n=f)
**Ungolfed:**
```
Fill ← {
  Height Width ← ⍴ Mask ← ' '=⍵
  Fixed   ← 0@Height⊢Mask
  ⍝ The initial interior piece is identified by the first occurence of <wall><no wall>
  Opening ← ⊂0 1+⊃⍸0 1⍷Mask
  ⍝ Iteratively expand the interior to the right, left and bottom
  Deltas  ← (1 0)(0 ¯1)(0 1)
  Volume  ← ≢ Interior ← {∪⍵,(⌷∘Fixed¨n)/n←⍵~⍨,Deltas∘.+⍵}⍣≡ Opening
  Bottom  ← Height⌷Mask
  ⍝ There is an hole when air on the bottom is below an interior point
  Hole    ← ⊃⍸Bottom∧Interior∊⍨(Height-1),¨⍳Width
  ⍝ If there is no hole, fill the interior
  0=Hole: '~'@Interior⊢⍵
  ⍝ Otherwise expand the matrix downwards and fill the column below the hole
  ⍝ and the spaces on the last row
  Drip    ← 0⌈Volume-+/Bottom
  '~'@((Height,¨⍸Bottom),Hole,⍨¨Height + ⍳Drip)⊢⍵↑⍨Height+Drip
}
```
[Read it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=VVOxbtswEN3zFbfZgpRGWoukCIIiaIYiS9HOtETHRGnSoJjKQZEMLRAoggW0W5YOdYcYWTqkhTv7U/glvSMl151E3Z3eu/cedSqkBHf7BT7uAbzi4mJi4Z0o7MQXXfsLXrPyvX8ZwODItb9x7lTMeQHgq@lx@Mo1S5rErmu/wZsJB6GEFUzi03IjtIGZ4DmWSxAFV1aMBYKMrsDi7FiY0oLO80vDFQ7pMRxWTMoXh0qDPyDw@YwroS7CZs2nFLLYNZ9d@wdPrl3v0J8hI7PiA5dXwOczpgrPst3Eav9uaPEEJB9boJmRtlZPEeMll5aVQeAwgzQaprD5mdEji7D/VsvLKQ99d7eEsx7YO@nqR/QpGbrF2tX33qzNSkUHCrvYuHHtKgkM2H4WY@natT/c3fdeITKc@FUCQ2fwYv2/wcZ7yRRMtORQTbgCJgxo5bUFLTQx4lJXNPcvCI1Hyps@7HIMTgZaVz/0ilzd4LrDsMJ@FiWblWuf/A3pvR4TX1gGw6JlEswTr9Wu5TicHhHfcxjcDI638M0yXClCOiecSpR8N7Mps0bModCVqpgpSh/UFj6nIFQnkQpE38H1COWM5bzsfZEML5rRFaVsxKyXn7pFHVLdjw9O@ntAqw478V55Z1CUkJQEndmsup8mRs4nQoyCJnf7FduhGVN97/ov&f=XVE7DsIwDN17ild1yMJQSvhOVQcmJsRciaFCiE4UpLIyMCAhcQYkbsCJchL8SVqEG@c59rPdOJuqOcHdnnD318A93u5@Xe7rOorMutqd6@1xYaINc0aYucfHJBBJkCiQkgCeZTEcMS2OY3gRKxwDqBM9hxxdozFXsOS2lgpaER@cYMpBoKAPXgupUXjoA@zp/yvlxKZpANkIZEFN9XRiIrOqtodLf/s5p6ep0AnE8hudfhtlzCzLMlyOjXBS0OAPoQzpmd4vz3OwggB/g9GZ8wvw4JOurwTbFi0poJtAV1peJkNGy3wB&i=AwA&r=tryapl&l=apl-dyalog&m=tradfn&n=f) Apparently this doesn't run with the comments on there, so if you want to have to run this version, you'll have to remove the comments.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 76 bytes
```
ＷＳ⊞υι≔Ｅυ⭆ι⎇∧∧⁻…ιμ ⁻✂ιμＬι¹ ⁼ λ~λη¿⁼§η±¹⊟υη«υ≔⊟ηζ⟦⭆ζ⎇⁼ ι~ι⟧Ｅ⁻№⪫ηω~№ＫＡ~⭆ζ§ ~⁼~λ
```
[Try it online!](https://tio.run/##TVDBasMwDD03XyFyksGD9LxTKDt0rCPQ3cYOIfViU8/pYntdO7Zfz6Q4IQ1Elp6e0HtqdN03XW2H4ayNVYBbd4phH3rjWhQCqug1RglG3Gel96Z1uKtPjCQOF0bCi@pd3V@wdIfx3xkXPW4ujVUb3Y2UDyEhh5xiau6tadTYkPCkXBs0GmquJxo9D5@xth6pkmAZyP9SRqkmPeYdcOKUYesO6hu1hGfV1kHhmlkVrY6CbZDWgDykrFfwk60SEglZTb6YrGnoylhqvy4mr4vJW11mlmWEeFsGeWK6QRepfuyMY3HnRKeY8EqpY2ktTrC4PSttnG3lwCvmvfMVBO37HYaiAP6KIoMxpZBxLICqbLj7sv8 "Charcoal – Try It Online") Link is to verbose version of code. Takes input as a rectangular list of newline-terminated strings. Explanation:
```
ＷＳ⊞υι≔
```
Input the bowl.
```
Ｅυ⭆ι⎇∧∧⁻…ιμ ⁻✂ιμＬι¹ ⁼ λ~λη
```
Try to fill the bowl with water.
```
¿⁼§η±¹⊟υη«
```
If the bowl isn't leaky, then output the filled bowl. Otherwise:
```
υ
```
Output all but the last row of the bowl.
```
≔⊟ηζ
```
Get the last row of the leaky bowl.
```
⟦⭆ζ⎇⁼ ι~ι⟧
```
Flood it and output the result.
```
Ｅ⁻№⪫ηω~№ＫＡ~⭆ζ§ ~⁼~λ
```
Count how much extra water there is and output just the hole of the last row of the leaky bowl for each extra line needed.
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), ~~256 251~~ 223 bytes
```
lambda s:[[*map(F,s)],s+[(b:=s.pop()).replace(E,W)]+[E*(h:=F(''.join(map(max,zip(b,s[-1])))).find(W))+W]*(sum(F(x).count(W)for x in s)-b.count(E))][h>-1]
E,W=' ~'
F=lambda s:E*(len(s)-len(s.lstrip()))+s.strip().replace(E,W)
```
[Try it online!](https://tio.run/##rVLbbuIwEH33VwziAbvQiLY8rJCyQkjlF/qQJigQs6SbixUHNd0H/zo741wINLvqSusk47mdmeOJ1Ud5zLOnb6o4H9zXcxKmuygEvfS8uzRUfDPTwp/pqcd3S1c7KldcCKeQKgn3kj/PXoQ/9Z7v@HHpbvhk4rzlccYJmIbV7Fes@G6mvfsHX@ByDnEW8Rchpi/@HdenlG94JZx9fspKdB/yAiqIM9Diftd4n4XwveN3LMCwlzsBM2EbtyOJjROZcQTYzUl0WcTEUEy10@hXZM@RPIAKo@0uf084CbFkAEh2ixXAJc3SR2sGNi4wXsjyVGTgJXEmneTtpEveQAQQbfITcwL4jFGTQrZdqAMpWN3zGbwf40TCA7WtcS4i1akkpg1lCsUHyPLSZthUgB2W/EkqFXNCpSROk@KY3xC8PhljvV4yVeXHtuHRI0ehSsl9KaPtIU4SGQ0lXRXYpnFR5IWM6EREwFsu8Q9dTeKS7f@hw5eqDOB8InPN9MAv7ehAYyjiH8eSxmHLyVB/wD5PVVjEOs6zTwW6ufXc9tCqiPEWTl6z5mb346KLX7Srsu4gf3HDvz@H/kE6/7@fqF9y6GhXpT8R76Hdv/850Z@Qe7NwZhg/j@3dhTEDq42BToMLgLGxsYtidu/HRqMRNGs0YlY2FrDGO@pZtWNUA02zWmBjXYA96wJcoLpAuSBJC12YiIZZmM4FsMYHwSjwY2tbYt3trR/FmvJIMTUAixHAkll3e@vvAFprABTo0fYlotoquls2zZgmDZUmzdymzeeW2HzOwKooGMk5zKnZUNgYDJu5MfWEDAAMaiwIgnaGAflbM6iT6nDQzTnA58ug9h8G@HQVqO9/NthqtQL80It732HMCh@D19Te3zHeXZRjkrcuusJUbkCyqoKqYhVarUQbBgOmquqhD1d6hEf71YpB5Tc "Python 3.8 (pre-release) – Try It Online")
A function taking in a list of strings representing an empty bowl, and output a list of strings representing the filled bowl. The input must be padded with whitespaces so that each line is the same length.
# Explanation
`F` is a helper functions for filling a line with water between the walls. This is done by stripping all leading and trailing whitespaces, replace the remaining whitespaces with water, then add the leading whitespaces back.
`f` is the main function, and has the structure:
`[answer_if_not_leak, answer_if_leak][has_leak]`
* `h:=F(''.join(map(max,zip(b,s[-1])))).find(W)` is the the index of the hole. This is done by first merging the walls of the bottom 2 lines (`b` and `s[-1]`), then fill the merged line with water. The only position that has water must be the hole:
```
L1     |  xxx        xx  |
L2     |    xxxx xxxx    |
Merged |  xxxxxx xxxxxx  |
Filled |  xxxxxx~xxxxxxx |
```
* If the bowl doesn't leak, there's no hole. So `h>-1` indicates that there's a leak.
* If no leak, simply applies `F` to each line
* If there is a leak, we returns a list consists of:
	+ Every line except the bottom: `s` (note that we used `b:=s.pop()` so the bottom is already removed)
	+ The bottom, with all whitespaces replaced with water: `[(b:=s.pop()).replace(E,W)]`
	+ The rows representing leaking water stream: `[E*h+W]*number_of_water_in_the_stream`
[Answer]
# Python3, 522 bytes:
```
from re import*
r=range
g=lambda x:[i for i in r(len(x))if i and i<len(x)-1 and findall('^(?:[^\s]|\s)\s+$',''.join(x[i]))and any(d!=' ' for d in x[i-1][1:])and any(d!=' ' for d in x[i+1][1:])]
f=lambda x:'\n'.join(sub('(?<=[^\s])\s+(?=[^\s])',lambda x:'~'*len(x.group()),l)for l in k)if not(j:=g([*zip(*(k:=x.split('\n')))]))else'\n'.join(k[:-1]+[sub(' ','~',k[-1])]+[' '*j[0]+'~'+' '*(len(k[-1])-j[0]+1) for _ in r(sum(len(findall('(?<=[^\s])\s+(?=[^\s])',n)[0])for n in k[:-1])-k[-1].count(' ')+(k[-1].count(' ')==1))])
```
[Try it online!](https://tio.run/##fVBtj6IwEP7eXzHIJW1FDez54UKWaPwbCBf2FK@KhVBM2Mtl/7o3M6JuNnotfZiXp/PMtHnvftf2@4@mPZ/Ltj5CuwVzbOq2G4s2aQu724pdUhXHt00BfZwaKOsWDBgLraq2VvVamxIDhd2Aeb1EphG7pbGboqqUzNUiTvO1y/6unV674JucSDnb1wbJqcm0JnZh39XGSyRIltiQBGanUZZGcfY/SjBQMlHeO5VrO0i405uSavGacAukrxaDLSd3/occc/ezXVufGqX1pNKkUpHKgYa0daf2cbJT6fiPadRYHeKkn7mmMp0iOa01zrKt3PYufkhjnCBIuQnAuT/k5JBiSGMQA@N9GmYBRgNy@EUv6SknIs2T/ry8tzsdmXF72GdTWY2XuXvL3XMTesqVZ7/qk@2oGR2or5EkiWiIs0tGo1EYAq0wFMAmgiAMAT3Mi6Y1eK9UTmvBN/I8h2HlgiD/5JCb3x2ycD@ss1wuAQ8S8f9Ey8cCvvDBJ/QRH7L6Hvpe9Mi9IvpPKr7Ai8DzVI0FgS2fXsIn2celPM@7Dul5gnHwQAxR75N3CXiPa80xOxdzmBPSesgCWOHGegh4xIqrrm7/axxhtXrStXMOAAFJjj/qzrHhbuvLzfM/)
[Answer]
# [J](https://www.jsoftware.com/),(Version 903) 270 bytes
```
fb=:{{((y~:' ')+.(*./\"1 &.|."1 y=' ')+.(*./\"1 y=' '))}'~',:y}}
l=:{{'~' e. {."1 (]#~"1' '&~:) |."1|: fb y}}
flb=:{{
lr=.{:I.+./"1 '~'= fy=.fb y
lb=.(lr{(' '=y)} y,:'~') lr} y
r=.('~'=lr{fy){' ~'
c=.-/+/"1^:2 '~'=fy ,: lb
lb, ((c,#r)$r)
}}
cgb=:{{>(l y){(fb y);flb y}}
```
With comments:
```
NB. FillBowl
fb=:{{((y~:' ')+.(*./\"1 &.|."1 y=' ')+.(*./\"1 y=' '))}'~',:y}}
NB. LeakyBowl?
l=:{{'~' e. {."1 (]#~"1' '&~:) |."1|: fb y}}
NB. Fill Leaky Bowl
flb=:{{
lr=.{:I.+./"1 '~'= fy=.fb y NB. leak row
lb=.(lr{(' '=y)} y,:'~') lr} y
r=.('~'=lr{fy){' ~' NB. dripping row
c=.-/+/"1^:2 '~'=fy ,: lb NB. add c dripping rows
lb, ((c,#r)$r)
}}
cgb=:{{>(l y){(fb y);flb y}}  NB. Code Golf Bowl solution
```
# [J](http://jsoftware.com/),(Version 806) 320 bytes
tio.run currently only has an older version of j without the direct definition syntax:
```
fb=:3 : 0
((y~:' ')+.(*./\"1 &.|."1 y=' ')+.(*./\"1 y=' '))}'~',:y
)
l=:3 : 0
'~' e. {."1 (]#~"1' '&~:) |."1|: fb y
)
flb=:3 : 0
lr=.{:I.+./"1 '~'= fy=.fb y
lb=.(lr{(' '=y)} y,:'~') lr} y
r=.('~'=lr{fy){' ~'
c=.-/+/"1^:2 '~'=fy ,: lb
lb, ((c,#r)$r)
)
cgb=:3 : 0
>(l y){(fb y);flb y
)
echo b1 ; cgb b1
echo lb1 ; cgb lb1
```
[Try it online!](https://tio.run/##fU5BTsMwELz7FZMGNTYNjlNurtwjEhJPACMlakqRBSjtxUqbr4e1k0Zw6Vqyd8czs/M5VKXR7@VFbl@ecPxxh9Px1B6@9lDQUCxFrJQhnV6kVEwwVq1vCZMkwVRJwuI9TWATmvyZRoAmMna3IykV6UoxxDY0dCn6iuKbsay11302bL6Odowxfts5k6VDrkNTGf0YDTj3vc6QiZXk97J4XZRYyrOkx5v/8DiLS9Znufbk4q4ehGAn0QUVf0v7RUnMZa8FgtFZo6kQBI2b17rWyE4/y5UsSEQGBo03MhKJJblrO04uxosLfK6JIeBa6hkpeRAQo/Giy9BnrDbyoViRldXr6NZ45BquIrMcnNd52oq7VlCIej@H2HIHcuBhq9hQupiS7eqPb1QlNiAuNSPgZoS6YfgF "J – Try It Online")
## Explanation
I'm still relatively new to J and this solution could probably be made shorter again by someone with more experience golfing in J.
We define three helper verbs (J terminology for functions) `fb` "FillBowl", `l` "IsBowlLeaky?" and `flb` "FillLeakyBowl" and then finally a main verb `cgb` "CodeGolfBowl" to tie them all together.
All three verbs take a rectangular 2 dimensional array of characters as argument y.
### `fb` "FillBowl"
```
fb=:{{((y~:' ')+.(*./\"1 &.|."1 y=' ')+.(*./\"1 y=' '))}'~',:y}}
```
`fb` creates a boolean mask of not-spaces and spaces from the sides and then uses the mask to index into either water ('~' array) or the original argument.
Eg:
```
   y
#      #
 #    # 
  ####  
   ((y~:' ')+.(*./\"1 &.|."1 y=' ')+.(*./\"1 y=' '))
1 0 0 0 0 0 0 1
1 1 0 0 0 0 1 1
1 1 1 1 1 1 1 1
   
```
### `l` "IsBowlLeaky?"
```
l=:{{'~' e. {."1 (]#~"1' '&~:) |."1|: fb y}}
```
`l` fills the bowl ignoring whether it leaks or not and then checks if the bottom non-whitespace row contains any water ('~' chars). If it does then the bowl is leaky.
To check for the leak we transpose the array to the right, delete leading spaces and then check if any water '~' is in the first column.
Eg:
```
   y
00     00
 00   00 
  000 0  
   fb y
00~~~~~00
 00~~~00 
  000~0  
   (]#~"1 ' '&~:) |."1 |: fb y
0  
00 
00~
0~~
0~~
~~~
00~
00 
0  
   
```
### `flb` "FillLeakyBowl"
```
flb=:{{
lr=.{:I.+./"1 '~'= fy=.fb y
lb=.(lr{(' '=y)} y,:'~') lr} y
r=.('~'=lr{fy){' ~'
c=.-/+/"1^:2 '~'=fy ,: lb
lb, ((c,#r)$r)
}}
```
`flb` proceeds with the following logic:
* Find the leaky row index `lr`
* Create the leakybowl array `lb` with the leaky row flooded
* Create the dripping row `r` with the drip in the correct location
* Count `c` how many water drops are missing
* Append `c` dripping rows `r` to the leakybowl array `lb`
### `cgb` "CodeGolfBowl"
```
cgb=:{{>(l y){(fb y);flb y}}
```
Finally our `cgb` verb combines everything together with the following logic:
* Create a boxed array of both the filledbowl and filledleakybowl solutions `(fb y);flb y`
* Check if the bowl is leaky `(l y)` and use the boolean 0 or 1 as the index into the previous boxed array
Eg:
```
   y
00     00
 00   00 
  000 0  
   (fb y);flb y
┌─────────┬─────────┐
│00~~~~~00│00     00│
│ 00~~~00 │ 00   00 │
│  000~0  │~~000~0~~│
│         │     ~   │
│         │     ~   │
│         │     ~   │
│         │     ~   │
└─────────┴─────────┘   
```
For more information on this fascinating and fun language the J wiki has a huge amount of information and also links to quite a few free books:
* [GettingStarted](https://code.jsoftware.com/wiki/Guides/GettingStarted)
* [Books](https://code.jsoftware.com/wiki/Books)
[Answer]
# Python 3, 387 365 bytes
```
from re import*
def l(b):
    s=b[-1];r=search;l=len;m=r("^( *[^ ]+)(.*?)([^ ]+ *$)",b[-2])
    if r("^.{"+str(l(m.group(1)))+"}[^ ]{"+str(l(m.group(2)))+"}",s):b=[r("^ *(?=[^ ])",x).group(0)+x.strip().replace(" ","~")for x in b]
    else:b[-1]=s.replace(" ","~");b+=[" "*l(r("^( *[^ ]+)",s).group(0))+"~"]*(sum([x.strip().count(" ")for x in b[:-1]])-s.count(" "))
    return b
```
[Try it online!](https://tio.run/##zVfbjtowEH3PVxhTqTZQlKU8VKBoKVLbD@i@ZZOKi9lNFZLIDlWqqv51OnYuC8QpRm2lOpCEMzNnLg7RTPY9f06Tt@8yfjzueLpHnKFon6U8HzhbtkMxWdOZg2AJb@2/uQvm3BNsxTfP89iLWTLfe5zgkKCBH6JgSMl4cE@JvkeDVxSPwGgS0Ept/AMPRc5JTPbjJ54eMnJHKR3in8qgJZuUMjwSVEcQ7dB@tvZ8xYQG5N5TVuCioJWBS4fFGDiijNAxZ1m82jCCER5hieku5ahAUYLWgWZjsWAznZInWsrz9dDz4ccgJmfpqVgaZxCcxMGAiMOe@C@ON@khyRXTiUt/Bn4C@kacSMukOMsPPMGPCR5/TaMEyn3Mmci/bFaCCeQhX2sRfVbLb@7Uwv3y2sejcxxpQR@1cNSHBTcNHIxQJ7nUy0CuYRtyOvp9/L1er77v9dp8qBb3DM60uNctLOU9u1xBUVarI5BK2BlIt9AQyLW6TOE0vSSboqkBVMsqxSlE2DaXU3mV81q0CC3haCcPGHwv4aW@LC3hDhLAlkvL5xh0pTE8KIghPL3PS0u4g6Qd3rUaCiHgJStEm0noj@HJEiZcNMuqNqAnpdkt4Ga30tbttZxdV19dt@VFS@DUdu8C6lpu/O38UgK/dKU0/pFvQ@3rEIZhfR8ayGppaHRUGoddb54QDqti/Ysg6ldqCEdXgOj/ltjv4mKxQPBtcwFs@cB2UEi5gOOWWPqmpqAPDUEb7CvQqh24hdPQNZjrbI/ZZ18UqCguOQo42YFgbLlff@hIFoWUf71OI/tCTdDkkkJBNqmbTOWpKXUCx8lWouxjH/iBOaohjkZINbiqLWbJYc/4KmfkpeWtpo2MR6pNfkwekwelrWQzyG@I1IwQVc0zKzK2ydkW@F86aMXl3wV1e71h0TetEZcSt5LUHvIPFckMGCr@mpfSi2DyT2l@olezt8OBeYBXAwFqxoBaPhZZHGlCTIPLMI2WtbxtqUuqVVbJEyMwkp1EP2t2A2anJM2bCPwoQJ7X0MLP2dlWNtv2cQVjkuOAeQmd7c77OC73shxWtMYWU0ePVqeKn9M9O9XcRtvkda4NMD3@Ag "Python 3.8 (pre-release) – Try It Online")
Takes input as a list of strings and returns a string representation of the bowl.
The first line sets up variables and then checks for bowl leaky-ness. The second line deals with non-leaky bowls, replacing spaces from the whitespace trimmed version of each line with `~`. The third line deals with leaky bowls, first filling the bottom row with water, then adding extra lines on the bottom as many times as is necessary.
Just out of interest, this answer, and I would guess most, are able to use bowls made of `~` characters, it is just confusing to look at.
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 315 308 303 bytes
```
e=enumerate
def f(b):
 for y,l in e(b):
  s=0
  for x,c in e(l):
   if c==" ":
    if s and(L:=b[y])[x:].strip():
     if y<len(b)-1:b[y]=L[:x]+"~"+L[x+1:]
     else:return[n.replace("~"," ")for n in b[:y]]+[l.replace(" ","~")]+[" "*x+"~"]*max(0,"".join(b).count("~")-l.count(" "))
   else:s=1
 return b
```
[Try it online!](https://tio.run/##RU9BjoQgELz7ig4XYXTMmL1syPIDf8Biog5m3TBIQBO8zNddEM12J6Srq7q6MdvyM@uPT2P3XTKp15e03SKzpxxhxD2hGYyzha1UMGmQqQOOPcIbCV8OiVAHAdMIA2MI0IEidNDpJ24o6/kmCPdUVG6xk8Fp4NBsX0rq4H2vaVSxhlMvCvRGRcN9UVORlFI5Sa1cVqu5rqw0qhskDrIyLCTxHB2P6TndhCi4@pdAkLwRCc1Q3ny0FrdX5/GjRKj6nae4vRrmVS/Rj9zVBYIxya7djtUZpAOg342douJbnw4jzvO8bVs4o41zF2zTFxJ9gliFDFOVM2pKXiTE/gc "Python 3.8 (pre-release) – Try It Online")
Takes a list of strings (each representing a line) and outputs a modified version of that list. Input must be padded to a rectangle.
Not the smallest Python solution here, but I wanted to try a more standard iterative approach. If anyone has ideas on how to make it smaller it'd be much appreciated!
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 314 bytes
```
(r,l=r.pop(),w=t=>t.replace(/ /g,'~'),m=r.reduce((a,c)=>a+(s=t=>t.split` `.length-1)(c.trim()),0))=>((q=l.trim()).search` `>0|q.length<s([...r].pop().trim())?[r,w(l),[...Array((m-=s(l))<0?0:m)].map(_=>'~'.padStart(l.search`\\S `+2))]:[r.map(v=>v.trimEnd().replace(/( *\S)( +)/g,(_,x,y)=>x+w(y))),l]).flat().join`
`
```
[Try it online!](https://tio.run/##PVBBbsIwELznFb5ltzEm9Ag4qIe@gCOJiJUYCHISY7sQpKpfTxdoerHk2Zmd2Tmrq/KVa2yYdX2tx6rvfGAHOYLjRjphewvIbzLILAinrVGVhjmbH3n8EyNvieJ0/UUgKF6hzFQC/sX21jShZKUwujuG02yBUIngmhYQeYrEBbhIM0HCa@WqEwmy9PvyJ1p72AkhXPEKMnE3O8dvYJA/hh/OqTtAO5OeIFynm3TZYiFaZWEvM8oprKq3QbkAZnLJ8y0rk3fEYrlzT@pVZtfn/s@uJqf/W4G95VsEliAdDXs@8DtFH5Ib3JEOMQWKg1GBJOe@6cqoHFdR9KixN1qY/ggHKKNhYMMQDYyx6aU/Y1EpvGnIZcGpnldjEOddTJtX4y8 "JavaScript (Node.js) – Try It Online")
Expects input as an array of strings, each representing a line. Outputs a string with the bowl.
]