Esempio n. 1
0
        static void Main(string[] args)
        {
            var tmp = PermutationAndCombination <string> .GetPermutation(new string[] { "word", "good", "best", "word" });

            var tmpList = new List <string>();

            foreach (var item in tmp)
            {
                string str = string.Empty;
                foreach (var sub in item)
                {
                    str += sub;
                }
                tmpList.Add(str);
            }
            string     testStr = "barfoothefoobarman";
            List <int> res     = new List <int>();

            for (int i = 0; i < tmpList.Count; i++)
            {
                if (testStr.Contains(tmpList[i]))
                {
                    res.Add(testStr.IndexOf(tmpList[i]));
                }
            }
        }
        public void CombinationCombinationTest()
        {
            var warriors = new Warrior[] {
                new Warrior(1),
                new Warrior(4),
                new Warrior(5),
                new Warrior(3),
                new Warrior(2),
            };
            var listCombination = PermutationAndCombination <Warrior> .GetPermutation(warriors);

            foreach (var combination in listCombination)
            {
                try
                {
                    //Console.WriteLine(string.Join("-", combination.Select(c => c.m_internal.ToString())));
                    Warrior.ResetCompareCount();
                    var result = WarriorSelectMedian.SelectMedian(combination);
                    //Console.WriteLine(Warrior.CompareCount);
                    Assert.AreSame(warriors[3], result);
                    Assert.AreEqual(true, Warrior.CompareCount <= 6);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + string.Join("-", combination.Select(c => c.m_internal.ToString())));
                    //Assert.Fail(ex.Message);
                }
            }
        }
    public void Call_test()
    {
        int[] arr = new int[6];
        for (int i = 0; i < arr.Length; i++)
        {
            arr[i] = i + 1;
        }
        //求排列
        List <int[]> lst_Permutation = PermutationAndCombination <int> .GetPermutation(arr, 3);

        //求组合
        List <int[]> lst_Combination = PermutationAndCombination <int> .GetCombination(arr, 3);
    }
Esempio n. 4
0
        //组合3中奖判断: 组合数另外计算 listSum
        public static string DisorderThree(int[] Boon, int[] Choose)
        {
            int numberWin = 0;      //标记选中的号码个数
            int n         = Boon.Length;

            //选号的组合方式
            List <int[]> ListCombination = PermutationAndCombination <int> .GetCombination(Choose, 2);

            //组三的复注选号列表

            List <int[]> listSum   = new List <int[]>(new int { });
            List <int[]> ListThree = PermutationAndCombination <int> .GetPermutation(Choose, 2);

            foreach (int [] list in ListThree)
            {
                int[] listCopy = new int[] { list[0], list[0], list[1] };
                listSum.Add(listCopy);
            }
            Console.WriteLine(listSum.Count);
            //组三中奖,若开奖号未出现重号,则不可能开出组三奖
            bool signThree = (Boon[0] - Boon[1]) == 0 || (Boon[0] - Boon[2]) == 0;

            if (signThree == true)
            {
                return("未中奖" + "\n(投注数:" + ListCombination.Count * 2 + ")");
            }

            //组三中奖判断,用组合2的顺序,逐个对应中奖号的百位,十位,个位
            foreach (int[] arr in ListCombination)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        if (arr[j] == Boon[i])
                        {
                            numberWin += 1;
                        }
                        if (numberWin == n)
                        {
                            return("中奖" + "\n(投注数:" + listSum.Count + ")");
                        }
                    }
                    numberWin = 0;
                }
            }
            return("未中奖" + "\n(投注数:" + listSum.Count + ")");
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            int[]        source  = new int[] { 1, 2, 3, 4 };
            string       src     = String.Join("", source);
            List <int[]> ArrList = PermutationAndCombination <int> .GetPermutation(source);

            List <string> DesList = new List <string>();

            foreach (var item in ArrList)
            {
                var tmp = string.Empty;
                foreach (var sub in item)
                {
                    tmp += sub;
                }
                DesList.Add(tmp);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 前一到三直选玩法中奖判断
        /// </summary>
        /// <param name="Boon"></param>
        /// <param name="Choose"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static string Judge_Preorder_1to3(int[] Boon, int[] Choose, int n)
        {
            int numberWin = 0;                                                                         //标记选中的号码个数

            List <int[]> ListCombination = PermutationAndCombination <int> .GetPermutation(Choose, n); //选择Choose中的n排列方式

            foreach (int[] arr in ListCombination)
            {
                for (int i = 0; i < n; i++)
                {
                    if (arr[i] == Boon[i])
                    {
                        numberWin += 1;
                    }
                    if (numberWin == n)
                    {
                        return("中奖" + "\n(投注数:" + ListCombination.Count + ")");
                    }
                }
                numberWin = 0;
            }
            return("未中奖" + "\n(投注数:" + ListCombination.Count + ")");
        }