14
Task
Given a ASCII diagram of a loop
e.g.
....................
......@@@@@.........
......@...@.........
.....@@...@@@@@.....
....@@........@.....
....@........@@.....
....@@@@@@@@@@......
....................
....................
And a location on the loop
e.g.
(7,1)
You must find the inside and outside of the loop
e.g.
00000000000000000000
00000011111000000000
00000011111000000000
00000111111111100000
00001111111111100000
00001111111111100000
00001111111111000000
00000000000000000000
00000000000000000000
Specifications
You may take input for the diagram as a string separated by newlines or obvious equivalent
You will receive a coordinate on the loop (0 or 1 indexed) as part of your input. You may place your origin at any place you wish. You may take this coordinate in
(<row>, <column>)
,(<column>, <row>)
or as the linear position on the string. You may receive these data in any reasonable method. All characters on the loop will be the same as the character at that index.Preferred output is a 2 dimensional array of truthy and falsy values, however strings of
1
and0
separated by newlines or any obvious equivalent of the later two are accepted. The inside and outside must have different truth values but it does not matter which is which.A loop is defined as a group of characters such that they are all the same character (e.g.
@
) and so that every character in the loop has a path to the original character (The character at the coordinate of input) that only passes through that same character (Taxicab geometry No diagonals).The inside is all the loop itself and the places that cannot reach the edge of the diagram without crossing the loop.
The outside is everywhere else
This is code-golf
Can we also take the coordinates as linear coordinate in the string? – flawr – 2017-01-17T16:15:32.060
@flawr You may. – Post Rock Garf Hunter – 2017-01-17T16:16:45.153
Are we allowed to take the diagram as a matrix of characters, sth. like
[['.', '.'],['.', '@']]
instead of a string with newlines? – hbaderts – 2017-01-17T16:19:41.263@hbaderts That is an obvious equivalent – Post Rock Garf Hunter – 2017-01-17T16:20:16.297
1@WheatWizard Thanks for the additional test case! I would however recommend to put them into a snippet or in a gist / pastebin, in order to make the challenge a bit more decluttered=) – flawr – 2017-01-17T21:41:03.843
Can we assume the input will be at least 2x2? Or if it¡s for example 1xN (a single line) how is insideness defined? – Luis Mendo – 2017-01-17T23:40:48.277
@LuisMendo For a line the inside will be the "loop" and nothing else – Post Rock Garf Hunter – 2017-01-17T23:42:36.083
If I take the input as a linear coordinate into the 2D char array, can it be column-major (i.e. down, then across)?
– Luis Mendo – 2017-01-17T23:55:24.870@LuisMendo Go ahead. I don't care how you take the data in I am not concerned with data processing but more the underlying algorithm. – Post Rock Garf Hunter – 2017-01-18T00:00:56.353
@WheatWizard Thanks! Anyway my algorithm was flawed because it assumed the loop was convex :-( – Luis Mendo – 2017-01-18T00:02:52.710
Can we assume the loop character to be a specific character (like
'@'
)? Also, can we assume the other characters to be the same, and can we assume it will be a specific character (like'.'
)? – infmagic2047 – 2017-02-01T13:59:33.317Nevermind, I saw it is disallowed in the test cases. – infmagic2047 – 2017-02-01T14:12:24.273