Ejemplo n.º 1
0
        /// <summary>
        /// Tries every group against every other group
        /// </summary>
        private void CombineAll()
        {
            var hashes = container.GetHashes(); //do I need to copy?
            var count  = hashes.Count;

            for (int first = 0; first < count; first++)
            {
                for (int second = first + 1; second < count; second++)
                {
                    if (CountdownNumber.CanCombine(hashes[first], hashes[second]))
                    {
                        CombineTwoSets(hashes[first], hashes[second]);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void CombineTwoSets(int firstHash, int secondHash)
        {
            Debug.Assert(CountdownNumber.CanCombine(firstHash, secondHash));
            var firstList  = container.GetNumbers(firstHash);
            var secondList = container.GetNumbers(secondHash);

            //pre-allocate results list
            var results = new List <CountdownNumber>(3 * firstList.Count * secondList.Count); //3 is the magic number (of operations)

            foreach (var n1 in firstList)
            {
                foreach (var n2 in secondList)
                {
                    foreach (var op in  Enum.GetValues(typeof(ComboCountdownNumber.Operation)).Cast <ComboCountdownNumber.Operation>())
                    {
                        results.Add(new ComboCountdownNumber(n1, n2, op));
                    }
                }
            }
        }