28
2
A Window is an ASCII-art square with odd side length of at least 3, with a single character border around the edge as well as vertical and horizontal strokes in the middle:
#######
# # #
# # #
#######
# # #
# # #
#######
An MS Window is a window where the border is made only of the characters M
and S
. Your task is to write a program (or function) that takes a string and outputs a truthy value if the input is a valid MS Window, and a falsey value if it is not.
Specifications
- You may take the input as a newline-separated string or an array of strings representing each line.
- The border of an MS Window may contain a mix of M and S characters, but the inside will always be composed of spaces.
- You can choose to detect only windows with trailing newlines, or only windows without trailing newlines, but not both.
Test Cases
Truthy:
MMM
MMM
MMM
SMSMS
M M S
SMSMM
S S M
SMSMS
MMMMMMM
M S M
M S M
MSSSSSM
M S M
M S M
MMMMMMM
Falsey:
Hello, World!
MMMM
MSSM
MS M
MMMM
MMSMM
M S.M
sSSSS
M S M
MMSMM
MMMMMMM
M M M
MMMMMMM
M M M
MMMMMMM
MMMMMMM
M M M M
MMMMMMM
M M M M
MMMMMMM
M M M M
MMMMMMM
MMSSMSSMM
M M M
S S S
S S S
MMSSMSSMM
S S S
S S S
M M M
MMSSMSSMM
3This is a great twist on ASCII arts, a decision problem to detect a certain structure. – xnor – 2017-01-08T05:53:08.343
4@xnor I feel like we might want a different tag for reverse ASCII art like this. – Esolanging Fruit – 2017-01-08T05:55:22.220
2while not specific to ascii art, pattern matching might be a good choice for a new tag – Destructible Lemon – 2017-01-08T06:15:27.150
Can you add a test case or two where the string doesn't form a rectangular array? – Greg Martin – 2017-01-08T08:54:59.243
Would
MMSSM\nM S M\nMSSSS\nS M S\nMSSMS
be valid? (theM
s andS
s are not constant) – user41805 – 2017-01-08T09:57:34.567Related: Clean the muddy quartata-fish
– Blue – 2017-01-08T10:58:06.223Can we assume the strings of the array will always be the same length (i.e. right-padded with spaces if needed)? – Luis Mendo – 2017-01-08T11:30:22.290
Why are the last two Falsey examples not Truthy? I'm probably missing something quite obvious here. – Mast – 2017-01-08T13:55:52.043
@Mast, I think because there should be four square panes – Chris M – 2017-01-08T16:26:45.577
@ChrisM That does not appear to be part of the requirement though. – Mast – 2017-01-08T17:14:12.477
1@Mast, you are quite right! Maybe the challenge needs clarifying – Chris M – 2017-01-08T17:19:44.123
I suppose
M
is a valid MS window too? – Adám – 2017-01-08T19:15:59.290@Adám NO because A Window is an ASCII-art square with odd side length of at least 3, with a single character border around the edge as well as vertical and horizontal strokes in the middle (that's the first sentence of the challenge) yours has length 1 – edc65 – 2017-01-08T21:26:19.400
@Mast A Window is an ASCII-art square with odd side length of at least 3, with a single character border around the edge as well as vertical and horizontal strokes in the middle The last 2 falsey are not square (the first) and with more than 1 vertical and horizontal stroke in the middle (the last one) – edc65 – 2017-01-08T21:29:11.683
If we take the input as a single string, can we assume there's a trailing newline? – Patrick Roberts – 2017-01-08T21:46:46.593
@PatrickRoberts No, but you can decide whether a valid window has a trailing newline. – Esolanging Fruit – 2017-01-08T21:48:37.880
@Challenger5 hah, just now noticed your edit. Luckily my program still satisfies that requirement! – Patrick Roberts – 2017-01-08T23:00:37.277
Do we have to take into account different Windows / Linux line endings? – Mawg says reinstate Monica – 2017-01-09T08:54:49.383
@DestructibleWatermelon That tag used to exist but was removed some time ago, because it's usage was quite arbitrary. – Martin Ender – 2017-01-09T09:00:33.207
@edc65 I missed the last Falsey having an odd S, so I understand that one. The other one looks square though, 7x7. – Mast – 2017-01-09T17:29:39.943