Exemplo n.º 1
0
        /// <summary>
        /// 疊加遞增
        /// </summary>
        /// <remarks>eg: 1,2,3,5,8,13,21</remarks>
        private FindTheLawFormula Superposition()
        {
            // 第一個開始的數值
            var one = CommonUtil.GetRandomNumber(1, 3);
            // 第一個開始的數值
            var two = CommonUtil.GetRandomNumber(1, 3);

            // 構成
            List <int> numberList = new List <int>()
            {
                one, two
            };

            for (var index = 2; index < 8; index++)
            {
                numberList.Add(numberList[index - 2] + numberList[index - 1]);
            }

            FindTheLawFormula formula = new FindTheLawFormula()
            {
                // 自然數列表
                NumberList = numberList,
                // 填空項目編號
                RandomIndexList = new List <int>()
                {
                    5, 6, 7
                }
            };

            // 結果返回
            return(formula);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 定量遞增算法
        /// </summary>
        /// <remarks>eg: 2,5,8,11,14,17,20</remarks>
        private FindTheLawFormula Crescent()
        {
            // 第一個開始的數值
            var start = CommonUtil.GetRandomNumber(1, 5);
            // 遞增量
            var addValue = CommonUtil.GetRandomNumber(5, 9);

            // 構成
            List <int> numberList = new List <int>()
            {
                start
            };
            List <int> randomIndexList = new List <int>()
            {
                0
            };

            for (var index = 1; index < 7; index++)
            {
                start += addValue;
                numberList.Add(start);
                randomIndexList.Add(index);
            }

            FindTheLawFormula formula = new FindTheLawFormula()
            {
                // 自然數列表
                NumberList = numberList,
                // 隨機項目編號(填空項目)
                RandomIndexList = RandomIndexListOrder(randomIndexList)
            };

            // 結果返回
            return(formula);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 一組計算式答題的HTML內容作成
        /// </summary>
        /// <param name="items">3個計算式</param>
        /// <param name="parentControlIndex">答題書索引號</param>
        /// <returns>HTML內容</returns>
        private string GetHtml(FindTheLawFormula items, int parentControlIndex)
        {
            int           controlIndex = 0;
            StringBuilder html         = new StringBuilder();

            items.NumberList.ForEach(d =>
            {
                if (items.RandomIndexList.Any(_ => _ == controlIndex))
                {
                    html.AppendLine(string.Format("<input id=\"inputFtl{0}L{1}\" type=\"text\" placeholder=\" ?? \" class=\"form-control input-addBorder-2\" disabled=\"disabled\" onkeyup=\"if(!/^\\d+$/.test(this.value)) this.value='';\" />", parentControlIndex, controlIndex));
                }
                else
                {
                    html.AppendLine(string.Format("<span class=\"badge badge-info\" style=\"width: 50px;\">{0}</span>", d));
                }
                controlIndex++;
            });

            return(html.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// 定量遞增擴展(2個定值逐個遞增)
        /// </summary>
        /// <remarks>eg: 2,3,7,8,12,13,17,18</remarks>
        private FindTheLawFormula CrescentExt()
        {
            // 第一個開始的數值
            var start = CommonUtil.GetRandomNumber(1, 5);
            // 遞增量
            var addValues = new List <int>()
            {
                CommonUtil.GetRandomNumber(1, 3), CommonUtil.GetRandomNumber(4, 6)
            };

            // 構成
            List <int> numberList = new List <int>()
            {
                start
            };

            for (var index = 1; index < 8; index++)
            {
                start += addValues[(index + 1) % 2];
                numberList.Add(start);
            }

            FindTheLawFormula formula = new FindTheLawFormula()
            {
                // 自然數列表
                NumberList = numberList,
                // 填空項目編號
                RandomIndexList = new List <int>()
                {
                    5, 6, 7
                }
            };

            // 結果返回
            return(formula);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 數字排隊(從4個隨機數的排列中找規律)
        /// </summary>
        /// <remarks>eg: 1234,2341,3412,4123,1234</remarks>
        private FindTheLawFormula QueueUpBase()
        {
            List <int>    numbers = new List <int>();
            StringBuilder number  = new StringBuilder();
            List <int>    list    = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            int count = 0;

            // 數字隊列初始化
            while (true)
            {
                if (count == 4)
                {
                    // 初始化創建5位以便前4位數字的輪轉
                    numbers.Add(numbers[0]);
                    break;
                }
                numbers.Add(CommonUtil.GetRandomNumber(list));
                list.Remove(numbers.Last());
                count++;
            }

            // 構成
            List <int> numberList = new List <int>
            {
                Convert.ToInt32(string.Format("{0}{1}{2}{3}", numbers[0], numbers[1], numbers[2], numbers[3]))
            };

            count = 0;
            // 數字隊列集合作成
            while (true)
            {
                if (count == 4)
                {
                    break;
                }

                number.Length = 0;
                // 數字隊列輪轉(後一位數逐個逐個往前移動一位)
                for (int index = 1; index <= numbers.Count; index++)
                {
                    if (index == numbers.Count)
                    {
                        // 末尾放起始位上的數字
                        numbers[numbers.Count - 1] = numbers[0];
                    }
                    else
                    {
                        // 後一位數往前移動
                        numbers[index - 1] = numbers[index];
                        number.Append(numbers[index - 1]);
                    }
                }

                numberList.Add(Convert.ToInt32(number.ToString()));
                count++;
            }

            FindTheLawFormula formula = new FindTheLawFormula()
            {
                // 自然數列表
                NumberList = numberList,
                // 填空項目編號
                RandomIndexList = new List <int>()
                {
                    2, 3
                }
            };

            // 結果返回
            return(formula);
        }