Tango is a puzzle that consists of a 6x6 grid partially filled with moons (M) and suns (S) and two lists of coordinate pairs, which we will call = and ×ばつ . The goal is to fill the rest of the grid following these rules:
- Each cell must contain either M or S
- There cannot be more than 2 M or S next to each other, either vertically or horizontally
- Each row and column must contain the same number of M and S
- Cells corresponding to a pair of coordinates in
= must be of the same type
- Cells corresponding to a pair of coordinates in
×ばつ must be of the opposite type
Input
- Partially filled 6x6 grid
- List of coordinate pairs (
=) indicating the two cells must be equal
- List of coordinate pairs (
×ばつ) indicating the two cells must be different
You may receive the grid and pairs in any reasonable format.
Output: Solved puzzle
You may assume that each input has exactly one answer and that it can be solved via deduction, i.e. you should never have to make a guess.
Test cases
Notes:
- The coordinates are 0-indexed
- The leftmost top cell has coordinates
(row, col) = (0,0)
. denotes an empty cell
- Pairs are provided as follows:
(a,b), (c,d), (e,f), (g,h), ...
pair 1: (a,b) and (c,d)
pair 2: (e,f) and (g,h)
...
Test 1
Input
= (1,1), (2,1), (3,1), (3,2)×ばつ (1,2), (2,2), (1,3), (1,4), (2,3), (2,4), (3,3), (4,3), (3,4), (4,4), (4,1), (4,2)
.MSSM.
M....M
S....M
S....S
M....S
.SMMS.
Output
MMSSMS
MSSMSM
SSMSMM
SMMSMS
MMSMSS
SSMMSM
Test 2
Input
= (2,2), (2,3), (2,3), (3,3)×ばつ (3,2), (3,3), (2,2), (3,2)
MS....
M...SM
SM..M.
.S..MS
SM...M
....MS
Output
MSMMSS
MSSMSM
SMSSMM
MSMSMS
SMSMSM
SMMSMS
Test 3
Input
= (0,1), (1,1), (1,0), (2,0), (2,5), (3,5), (3,0), (4,0), (4,0), (4,1)×ばつ (0,1), (0,2), (0,3), (0,4), (0,4), (1,4), (1,0), (1,1), (1,4), (1,5), (1,5), (2,5), (2,0), (3,0), (3,5), (4,5), (4,4), (4,5), (4,4), (5,4), (5,3), (5,4), (5,1), (5,2), (4,1), (5,1)
......
......
..S.S.
.M.S..
......
......
Output
SSMSMM
MSSMSM
MMSMSS
SMMSMS
SSMMSM
MMSSMS
Test 4
Input
= (1,2), (2,2), (2,1), (3,1), (3,2), (3,3), (4,0), (5,0), (5,1), (5,2), (5,3), (5,4), (4,5), (5,5)×ばつ (1,3), (2,3), (2,4), (3,4), (4,1), (4,2), (4,3), (4,4)
..SS..
......
......
......
......
......
Output
SMSSMM
MSMMSS
SMMSSM
SMSSMM
MSMMSS
MSSMMS