예제 #1
0
        protected virtual int GetAperiod(IList <double> digits)
        {
            var aperiod    = 0;
            var dictionary = new Dictionary <double, int>();

            for (int i = 0; i < digits.Count; i++)
            {
                if (!dictionary.Any(d => Helpers.AboutEqual(d.Key, digits[i])) && !dictionary.ContainsKey(digits[i]))
                {
                    dictionary.Add(digits[i], i);
                }
                else
                {
                    if (aperiod < dictionary.Count)
                    {
                        aperiod = dictionary.Count;
                    }
                    i = (dictionary.ContainsKey(digits[i]) ? dictionary[digits[i]] : dictionary.First(d => Helpers.AboutEqual(d.Key, digits[i])).Value) + 1;
                    dictionary.Clear();
                }
            }

            if (aperiod < dictionary.Count)
            {
                aperiod = dictionary.Count;
            }

            return(aperiod);
        }
예제 #2
0
        protected virtual int GetPeriod(IList <double> digits)
        {
            var period = 0;

            var indexes = new List <int>();

            for (int i = 1; i < digits.Count; i++)
            {
                if (Helpers.AboutEqual(digits[i], digits[0]))
                {
                    indexes.Add(i);
                }
            }

            for (int i = 0; i < indexes.Count; i++)
            {
                var validPeriod = true;
                for (int j = indexes[i]; j < ((indexes[i] * 2 > digits.Count) ? digits.Count : indexes[i] * 2); j++)
                {
                    if (!Helpers.AboutEqual(digits[j - indexes[i]], digits[j]))
                    {
                        validPeriod = false;
                    }
                }

                if (validPeriod)
                {
                    period = indexes[i];
                    break;
                }
            }

            return(period);
        }