59
8
Background: Too many illegal immigrants from Blandia are crossing the border to Astan. The emperor of Astan has tasked you with digging a trench to keep them out, and Blandia must pay for the expenses. Since all typists have been furloughed until the trench is arranged, your code must be as short as possible.*
Task: Given a 2D map of the border between Astan and Blandia, make the Blands pay (with land) for a border trench.
For example: With Astanian cells marked A
, Blandic cells marked B
and trench cells marked +
(the map frames are only for clarity):
┌──────────┐ ┌──────────┐
│AAAAAAAAAA│ │AAAAAAAAAA│
│ABAAAAAABA│ │A+AAAAAA+A│
│ABBBAABABA│ │A+++AA+A+A│
│ABBBAABABA│ │A+B+AA+A+A│
│ABBBBABABA│→│A+B++A+A+A│
│ABBBBABBBB│ │A+BB+A++++│
│ABBBBABBBB│ │A+BB+A+BBB│
│ABBBBBBBBB│ │A+BB+++BBB│
│BBBBBBBBBB│ │++BBBBBBBB│
└──────────┘ └──────────┘
Details: The map will have at least three rows and three columns. The top row will be entirely Astanian and the bottom row will be entirely Blandic.
You may use any three values to represent Astanian territory, Blandic territory, and border trench, as long as input and output are consistent.
Automaton formulation: A Blandic cell with at least one Astanian cell in its Moore neighbourhood becomes a border trench cell.
Test cases
[
"AAAAAAAAAA",
"ABAAAAAABA",
"ABBBAABABA",
"ABBBAABABA",
"ABBBBABABA",
"ABBBBABBBB",
"ABBBBABBBB",
"ABBBBBBBBB",
"BBBBBBBBBB"
]
becomes:
[
"AAAAAAAAAA",
"A+AAAAAA+A",
"A+++AA+A+A",
"A+B+AA+A+A",
"A+B++A+A+A",
"A+BB+A++++",
"A+BB+A+BBB",
"A+BB+++BBB",
"++BBBBBBBB"
]
[
"AAA",
"AAA",
"BBB"
]
becomes:
[
"AAA",
"AAA",
"+++"
]
[
"AAAAAAAAAA",
"AAAABBBAAA",
"AAAABBBAAA",
"AAAABBBAAA",
"AAAAAAAAAA",
"BBBBBBABBB",
"BBBBBBAABB",
"BBBAAAAABB",
"BBBBBBBBBB"
]
becomes:
[
"AAAAAAAAAA",
"AAAA+++AAA",
"AAAA+B+AAA",
"AAAA+++AAA",
"AAAAAAAAAA",
"++++++A+++",
"BB++++AA+B",
"BB+AAAAA+B",
"BB+++++++B"
]
* DISCLAIMER: ANY RESEMBLANCE TO ACTUAL GEOPOLITICS IS PURELY COINCIDENTAL!
23Political satire in the form of code golf, I love it :o) – Sok – 2019-01-16T17:17:11.413
4-1 for that
<sup><sub><sup><sub><sup><sub><sup><sub>
:-P – Luis Mendo – 2019-01-16T19:44:11.110Does the input/output have to be a list of strings or are other formats acceptable? my preference is single string with newline separators. Others may prefer 2D array of characters, etc. – Level River St – 2019-01-16T21:00:34.343
@LevelRiverSt Anything that reasonably represents 2D is fine. A string with newlines is an obvious one. – Adám – 2019-01-16T21:27:13.077
25python, 4 bytes:
pass
The plans to build a border trench lead to a government shutdown and nothing happens. – TheEspinosa – 2019-01-16T21:43:53.5473@TheEspinosa No no, the shutdown is until the trench is arranged. – Adám – 2019-01-16T21:45:32.507
1I upvoted just because of the background story. Didn't even continue reading. – pipe – 2019-01-17T20:16:02.450