示例#1
0
 public AlphameticEquationSolverHelper(AlphameticEquation equation, bool allowRepeatingNumbers, bool allowLeadingZeros, bool findOneSolutionOnly)
 {
     Equation = equation;
     AllowRepeatingNumbers = allowRepeatingNumbers;
     AllowLeadingZeros     = allowLeadingZeros;
     FindOneSolutionOnly   = findOneSolutionOnly;
     CreateLetterNumberPairs();
 }
示例#2
0
 public void SolveEquation(AlphameticEquation equation, bool allowRepeatingNumbers, bool allowLeadingZeros, bool findOneSolutionOnly, Action <AlphameticEquation, Dictionary <char, byte> > onSolutionFound)
 {
     Equation = equation;
     AlphameticEquationSolverHelper[] alphameticEquationSolverHelpers = new AlphameticEquationSolverHelper[Environment.ProcessorCount];
     Parallel.ForEach(alphameticEquationSolverHelpers, (alphameticEquationSolverHelper, state, index) =>
     {
         alphameticEquationSolverHelper = new AlphameticEquationSolverHelper(equation, allowRepeatingNumbers, allowLeadingZeros, findOneSolutionOnly);
         long triesPerProcessor         = (long)Math.Pow(10, alphameticEquationSolverHelper.GetCountOfUniqueLetters()) / Environment.ProcessorCount;
         alphameticEquationSolverHelper.Solve(index * triesPerProcessor, (index + 1) * triesPerProcessor, onSolutionFound);
         if (findOneSolutionOnly)
         {
             state.Break();
         }
     });
 }
示例#3
0
 public static void PrintSolution(AlphameticEquation equation, Dictionary <char, byte> letterNumberPairs)
 {
     lock (printLock)
     {
         string solution = AlphameticEquationSolverHelper.TranslateAlphametic(equation.ToString(), letterNumberPairs);
         Console.WriteLine(equation.ToString());
         Console.WriteLine(solution);
         Console.WriteLine();
         PrintDictionary(letterNumberPairs);
         Console.WriteLine();
         for (int i = 0; i < solution.Length; i++)
         {
             Console.Write("-");
         }
         Console.WriteLine("\n");
     }
 }