Click here to Skip to main content
15,893,161 members
Articles / Artificial Intelligence

Sudoku using Microsoft Solver Foundation

Rate me:
Please Sign up or sign in to vote.
4.85/5 (36 votes)
26 May 2014CPOL6 min read 85.1K   2.2K   112  
An example of how to use Microsoft Solver Foundation on a constraint satisfaction problem.
using System;
using System.Collections.Generic;

namespace Sudoku
{
    public static class Utils
    {
        /* This method will return a list of unique random integers.
         * The minValue & maxValue will be used as the range.
         * count is the amount of random intergers that will be returned. */

        public static List<int> GetUniqueRandomNumbers(int minValue, int maxValue, int count)
        {
            List<int> randomIntegers = new List<int>();

            /* Check that the input parameters are valid */
            if (((maxValue - minValue) ) < count)
            {
                return null;
            }
            Random random = new Random();
            while (randomIntegers.Count < count)
            {
                int next = random.Next(minValue, maxValue);
                if (!randomIntegers.Contains(next))
                {
                    randomIntegers.Add(next);
                }
            }
            return randomIntegers;
        }

        public static int GetRandomNumber(int minValue, int maxValue)
        {
            return GetUniqueRandomNumbers(minValue, maxValue, 1)[0];
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Code Rain
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions