3
1
Inspired by Braille graphics
Given a Boolean matrix (i.e., consisting of only 1
s and 0
s), output an ASCII-art-style Unicode representation of the closed-polygon shape created by the 1
s in the matrix, using the Unicode drawing characters ┌ ─ ┐ │ └ ┘
(code points 0x250c, 0x2500, 0x2510, 0x2502, 0x2514,
and 0x2518,
respectively, separated by spaces). Replace the 0
s 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 1
s through the matrix. In other words, every 1
has exactly two cardinal neighbors that are 1
s, and two that are 0
s or out of bounds. Additionally, since the shape is a closed-polygon, this guarantees that the path is cyclical.
Examples:
[[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.
What are the codepoints for the relevant drawing characters? – Peter Taylor – 2017-08-31T18:24:26.403
@PeterTaylor Good point. Added. – AdmBorkBork – 2017-08-31T18:29:17.323
1
I believe this is a dupe since my Jelly solution works with this input TIO. It could probably be shortened since there will only be one path here instead of multiple like in the other.
– miles – 2017-08-31T18:44:09.447@miles Dagnabbit. I thought this was a duplicate, but 48+ hours in the Sandbox and several searches by me didn't find one. – AdmBorkBork – 2017-08-31T19:14:02.580
@AdmBorkBork The usual tip: after you type the title, a list with possible duplicates goes below the title. You can check there, although the titles in this case were quite different. – Erik the Outgolfer – 2017-09-01T08:08:04.540