(randomly inspired by this question)
Let's make a drawing from some pipes |
and hyphens -
. Choosing a subset, if chosen carefully, you can form a rectangular box or block shape (meaning that the corners are formed by |-
or -|
). For this challenge, we're concerned only with identifying the corners -- the vertical and horizontal pieces of the block shape can be made of either |
or -
, and the block may be hollow.
Here's the original drawing, and the subset showing a block shape.
|--|---| |--|---|
|-|||-|| --> | |
|------| |------|
However, note that the following subsets from this same example do not make a block, because the corners are not all -|
or |-
|--|
|-||
||-||
----|
|-|
---
Each combination of -|
or |-
can only form one corner. This means that the smallest possible block shape is these eight characters
|--|
|--|
and that these six characters do not form a block shape, since the corners are being "doubled up."
|-|
|-|
The challenge here is to turn these blocks fluffy. How? Replace every hard-edged straight character that forms the block edges (both corners and sides) with a much rounder, fluffier character, in this case, an o
. But, don't fill in the block - we only want to get rid of the hard edges and sharp corners.
|--|---| oooooooo
|-|||-|| --> o-|||-|o
|------| oooooooo
Input
A 2D string representation of the pipe/hyphen diagram. Input can be as a multiline string, an array of strings, etc., however is convenient for your language. The input is guaranteed to be rectangular (i.e., every row will be the same length), and will only contain |
and -
.
Output
The same diagram, with the "block" characters replaced with o
as described above and the remaining characters unchanged. The result can be printed to the screen or STDOUT, returned from a function, etc.
Rules
- Note that blocks can overlap (see example #8) and blocks can share corners (see example #5).
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Examples
#1
-|--|
|--|-
|--||
-|--|
oooo-
oooo|
#2
|--|---|
|-|||-||
|------|
oooooooo
o-|||-|o
oooooooo
#3
|||||
|||||
#4
|-----|
||---|-
||---|-
|-----|
ooooooo
ooooooo
ooooooo
ooooooo
#5
-|--|--|
|||-|--|
-|-----|
-ooooooo
|o|-oooo
-ooooooo
#6
|-||-|
|----|
oooooo
oooooo
#7
--|--|-
|-----|
--|--|-
|-----|
#8
|-----|---
||--||-|--
||||--|--|
|-|-||||-|
|--|--|-||
---||---||
---|-----|
ooooooo---
o|--||o|--
o||ooooooo
o-|o||o|-o
ooooooo-|o
---o|---|o
---ooooooo