This question already has an answer here:
- Connect the pixels 11 answers
Inspired by Braille graphics
Given a Boolean matrix (i.e., consisting of only
0s), output an ASCII-art-style Unicode representation of the closed-polygon shape created by the
1s in the matrix, using the Unicode drawing characters
┌ ─ ┐ │ └ ┘ (code points
0x250c, 0x2500, 0x2510, 0x2502, 0x2514, and
0x2518, respectively, separated by spaces). Replace the
0s with spaces, so you're left with just the line drawing. Output or return that drawing.
You won't have to handle invalid or ambiguous input - there will be only one unambiguous path of
1s through the matrix. In other words, every
1 has exactly two cardinal neighbors that are
1s, and two that are
0s or out of bounds. Additionally, since the shape is a closed-polygon, this guarantees that the path is cyclical.
[[1,1,1] [1,0,1] [1,1,1]] ┌─┐ │ │ └─┘ [[0,1,1,1,1,0], [1,1,0,0,1,1], [1,0,0,0,0,1], [1,1,1,1,1,1]] ┌──┐ ┌┘ └┐ │ │ └────┘ [[1,1,1,0,0] [1,0,1,1,1] [1,0,0,0,1] [1,1,0,1,1] [0,1,1,1,0]] ┌─┐ │ └─┐ │ │ └┐ ┌┘ └─┘ [[1,1,1,0] [1,0,1,1] [1,1,0,1] [0,1,1,1]] ┌─┐ │ └┐ └┐ │ └─┘
- Leading or trailing newlines or whitespace are all optional, so long as the characters themselves line up correctly.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- If possible, please include a link to an online testing environment so other people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.