Example #1
0
        public string Resolve(string input)
        {
            var lines = input.ToLines().ToList();

            lines.RemoveAt(0);

            var results = new List <string>();

            while (lines.Count != 0)
            {
                var line = lines[0];
                lines.RemoveAt(0);

                var chunks = line.ToChunks();
                _size = int.Parse(chunks[0]);
                var modelsCount = int.Parse(chunks[1]);

                _score = 0;

                _original = new int[_size, _size];
                lines.Take(modelsCount).ForEach(l =>
                {
                    var ch   = l.ToChunks();
                    var type = GetModelType(ch[0]);
                    var row  = int.Parse(ch[1]);
                    var col  = int.Parse(ch[2]);

                    _original[row, col] = type;

                    _score += GetStylePoints(type);
                });

                lines.RemoveRange(0, modelsCount);

                _modifiable = new int[_size, _size];
                _solution   = new int[_size, _size];
                _current    = new int[_size, _size];
                _original.CopyTo(_current, 0);

                var initial     = new State(-1, -1, 0, 0, _score);
                var backtraking = new Backtracking <State>(
                    expand: Expand);
                var result = backtraking.Begin(initial);

                results.Add("");
            }

            var output = results
                         .Select((x, i) => $"Case #{i + 1}: {x}")
                         .ToArray();

            return(output.JoinLines());
        }