Inspired by this little game.
Given as input the initial position of a grid (always 5x5), like this:
-ABCD -A--- ---C- ---BD --E-E
You need to connect the letters (same letters all together), removing all empty
- spaces. The letters will be always
A,B,C,D and E.
Every pair of letters must be connected by a single unbranched line that can bend at right angles (using the very same letter to depict the line).
The input is guaranteed to have each starting letter exactly 2 times and it will always have all starting letters A-E.
The input can be read from stdin, or one only string as arg to some function, or even an array/matriz/list of chars, the most convinient way to your coding-language.
Since this is code-golf shortest code in bytes wins!
There is not only one solution to each problem, but the rules apply to all (no empty space and no separated letters). And the input is guaranteed to have at least one correct output.
Let's start connecting the letters A:
AABCD AA--- AA-C- AA-BD AAE-E
Now, connecting the letters B:
AABCD AAB-- AABC- AABBD AAE-E
Now, connecting the letters C:
AABCD AABC- AABC- AABBD AAE-E
Now, connecting the letters D:
AABCD AABCD AABCD AABBD AAE-E
And, finally the letters E:
AABCD AABCD AABCD AABBD AAEEE
input: E--E- BB-C- AD--- ---C- AD--- output: EEEEE BBECE ADECE ADECE ADEEE input: A---- ---B- -C-C- -D-D- BE-EA output: AAAAA BBBBA BCCCA BDDDA BEEEA