FuzzyLife
TCO10 Qual 2 · 2010-04-11 · by Nickolas
Problem Statement
- Each live cell with less than 2 or more than 3 live neighbors becomes dead.
- Each dead cell with exactly 3 live neighbors becomes live.
- All other cells remain the same.
You are given a
Your task is to replace the unknown cells in the initial layout with live or dead cells in such a way that the total number of live cells after one step is maximized. Return the maximal possible number of live cells after one step.
Constraints
- grid will contain between 2 and 50 elements, inclusive.
- Each element of grid will contain between 2 and 50 characters, inclusive.
- All elements of grid will contain the same number of characters.
- Each character in grid will be '0', '1' or '?'.
- No cell will have more than one neighboring cell of type '?'.
{"011",
"0?1",
"100"}
Returns: 5
There is only one unknown cell on the board, and two choices of filling it: 011 011 011 011 001 -> 001 or 011 -> 101 100 000 100 010 The first choice produces 3 live cells, and the second one produces 5 live cells.
{"101",
"0?0",
"101"}
Returns: 4
Again only one unknown cell and two choices: 101 000 101 010 000 -> 000 or 010 -> 101 101 000 101 010
{"?11",
"100",
"100"}
Returns: 5
{"11",
"11"}
Returns: 4
It is possible to have no unknown cells.
{"111",
"1?1",
"111"}
Returns: 8
The number of live cells doesn't depend on the choice of the unknown cell. Remember that the cells outside of the described part of the grid can turn live as well.
{"0110",
"?00?",
"0110"}
Returns: 6
beehive
{"0?10",
"1001",
"0101",
"00?0"}
Returns: 7
loaf
{"?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?111?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001",
"10000000000000000000000000000000000000000000000001",
"?111?11?11?11?11?11?11?11?11?11?11?11?11?11?11?11?",
"10000000000000000000000000000000000000000000000001"}
Returns: 2546
presumably max test (2546)
{"00100",
"01010",
"10?01",
"01010",
"00100"}
Returns: 12
Choosing '0' as the value of an unknown cell is sometimes better.
{"10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01", "00100100100100100100100100100100100100100100100100", "10010010010010010010010010010010010010010010010010", "01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01?01"}
Returns: 2320
result is an almost solid square
{"00100100100100",
"01001?10010010",
"10?10001001001",
"00100100100100",
"01001010010010",
"1?0100?10?10?1",
"01001010010010",
"00100100100100",
"10?100?10?1001",
"01001010010010",
"00100100100100"}
Returns: 111
choose all 0
{"?1110",
"100?1",
"00001",
"?0010"}
Returns: 11
choose 0
{"110",
"1?1",
"011"}
Returns: 6
choose 0
{"111111",
"000000",
"0?00?0"}
Returns: 12
choose all 0
Submissions are judged against all 134 archived test cases, of which 14 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FuzzyLife with a public method int survivingCells(vector<string> grid) · 134 test cases · 2 s / 256 MB per case