Пример #1
0
        public SelectedNumInfo getNextSelectNum(int[,] question)
        {
            SelectedNumInfo result = new SelectedNumInfo();

            int minListCount = 10;

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (question[i, j] == 0)
                    {
                        continue;
                    }

                    if (map[i, j].Count < minListCount)
                    {
                        if (result.selectedIndex == map[i, j].Count)
                        {
                            continue;
                        }

                        result.selectedIndex++;
                        result.indexRow        = i;
                        result.indexCol        = j;
                        result.value           = (int)map[i, j][result.selectedIndex - 1];
                        result.possibleNumList = map[i, j];

                        minListCount = map[i, j].Count;
                    }
                }
            }
            return(result);
        }
Пример #2
0
        public int[,] solveAll(int[,] question)
        {
            int[,] result = (int[, ])question.Clone();

            ArrayList[,] map = makePossibleNumMap(question);
            SelectedNumInfo preSelectedNumInfo = new SelectedNumInfo();

            while (!finalValidate(result))
            {
                // select


                while (!validate(result))
                {
                    // pop
                    preSelectedNumInfo = (SelectedNumInfo)selectedNumList[selectedNumList.Count - 1];

                    // remove
                    selectedNumList.Remove(preSelectedNumInfo);

                    // rewind result
                    result[preSelectedNumInfo.indexRow, preSelectedNumInfo.indexCol] = 0;

                    // selected index ++
                    preSelectedNumInfo.selectedIndex++;

                    // check list end
                    if (preSelectedNumInfo.possibleNumList.Count == preSelectedNumInfo.selectedIndex)
                    {
                        break;
                    }

                    // update value
                    preSelectedNumInfo.value = (int)preSelectedNumInfo.possibleNumList[preSelectedNumInfo.selectedIndex - 1];

                    //push
                    selectedNumList.Add(preSelectedNumInfo);

                    // update result
                    result[preSelectedNumInfo.indexRow, preSelectedNumInfo.indexCol] = preSelectedNumInfo.value;
                }
            }

            return(result);
        }