Exemple #1
0
 private NumInfo PeekMaxInternal()
 {
     if (_maxValue == null)
     {
         _maxValue = _set.Max;
     }
     return(_maxValue);
 }
Exemple #2
0
 private NumInfo PeekMinInternal()
 {
     if (_minValue == null)
     {
         _minValue = _set.Min;
     }
     return(_minValue);
 }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ViewState["PreivousInfo"] != null)
            {
                o_Num = (NumInfo)ViewState["PreivousInfo"];
            }

            int i_Ind = (o_Num.i_BoundCount - 1);

            i_Num          = (o_Num.ia_List)[i_Ind];
            lb_Result.Text = i_Num.ToString();
        }
Exemple #4
0
        private static int GetNextIndexOfNotEqual(NumInfo[] sortedNumInfos, NumInfo numInfo)
        {
            for (int i = numInfo.Index + 1; i < sortedNumInfos.Length; ++i)
            {
                if (sortedNumInfos[i].Num != numInfo.Num)
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemple #5
0
    public void DisplayNumber(NumInfo info)
    {
        num            = info;
        button.enabled = false;

        view.Set(info);
        view.Display();
        view.ChangeColor(Color.white);

        on = true;

        view.Show(EnableButton);
    }
Exemple #6
0
                public int PopMax()
                {
                    _count--;
                    var max = PeekMaxInternal();

                    max.Count--;
                    if (max.Count == 0)
                    {
                        _cache.Remove(max.Value);
                        _set.Remove(max);
                        _maxValue = _set.Max;
                    }
                    return(max.Value);
                }
Exemple #7
0
                public int PopMin()
                {
                    _count--;
                    var min = PeekMinInternal();

                    min.Count--;
                    if (min.Count == 0)
                    {
                        _cache.Remove(min.Value);
                        _set.Remove(min);
                        _minValue = _set.Min;
                    }
                    return(min.Value);
                }
Exemple #8
0
        public IList <IList <int> > ThreeSum(int[] nums)
        {
            if (nums == null || nums.Length == 0)
            {
                return(new List <IList <int> >());
            }

            var nl       = nums.Length;
            var numInfos = new Dictionary <int, NumInfo>();

            for (int i = 0; i < nl; ++i)
            {
                var     num = nums[i];
                NumInfo numInfo;
                if (numInfos.TryGetValue(num, out numInfo))
                {
                    numInfo.Indices.Add(i);
                }
                else
                {
                    numInfo = new NumInfo();
                    numInfo.Indices.Add(i);
                    numInfos.Add(num, numInfo);
                }
            }

            for (int i = 0; i < nl; ++i)
            {
                for (int j = i + 1; j < nl; ++j)
                {
                    int     numI   = nums[i];
                    int     numJ   = nums[j];
                    int     target = -numI - numJ;
                    NumInfo numInfo;
                    if (numInfos.TryGetValue(target, out numInfo))
                    {
                        var indices = numInfo.Indices;

                        // ...

                        // here j is greater than i, so could get indices greater than j and return
                        // all the respectire [i, j, {found index}] triplet;
                        // should check for duplicate triplets then though
                    }
                }
            }

            throw new NotImplementedException();
        }
Exemple #9
0
    public NumInfo GetTaskNum()
    {
        int randIndex = Random.Range(0, nummeros.Count);

        //control not to reapeat the same number twice in a row, can be repeated later
        NumInfo newNum = GetRandomNumInfo();

        while (newNum.num == currentNum.num)
        {
            newNum = GetRandomNumInfo();
        }

        currentNum = newNum;
        return(currentNum);
    }
Exemple #10
0
        protected void bt_Equals_Click(object sender, EventArgs e)
        {
            switch (o_Num.i_Operater)
            {
            case 1:
                if (o_Num.i_BoundCount > 1)
                {
                    o_Num.ia_List[0] += o_Num.ia_List[1];
                    o_Num.ia_List[1]  = 0;
                    o_Num.i_BoundCount--;
                }
                break;

            case 2:
                if (o_Num.i_BoundCount > 1)
                {
                    o_Num.ia_List[0] -= o_Num.ia_List[1];
                    o_Num.ia_List[1]  = 0;
                    o_Num.i_BoundCount--;
                }
                break;

            case 3:
                if (o_Num.i_BoundCount > 1)
                {
                    o_Num.ia_List[0] *= o_Num.ia_List[1];
                    o_Num.ia_List[1]  = 0;
                    o_Num.i_BoundCount--;
                }
                break;

            case 4:
                if (o_Num.i_BoundCount > 1)
                {
                    o_Num.ia_List[0] /= o_Num.ia_List[1];
                    o_Num.ia_List[1]  = 0;
                    o_Num.i_BoundCount--;
                }
                break;

            default:
                break;
            }
            lb_Operate.Text = "";
            lb_Result.Text  = (o_Num.ia_List[0]).ToString();

            ViewState["PreivousInfo"] = o_Num = null;
        }
Exemple #11
0
                public static int Less(NumInfo a, NumInfo b)
                {
                    var i   = 0;
                    var ad  = a.Digits;
                    var bd  = b.Digits;
                    var len = System.Math.Max(ad.Length, bd.Length);

                    while (i < len)
                    {
                        var av = ad[i % ad.Length];
                        var bv = bd[i % bd.Length];
                        if (av != bv)
                        {
                            return(av - bv);
                        }
                        ++i;
                    }

                    return(0);
                }
Exemple #12
0
    public List <NumInfo> LoadNumbers()
    {
        List <NumInfo> nummeros = new List <NumInfo>();

        TextAsset fileData = Resources.Load <TextAsset>("numbersData"); //we load the csv as a TextAsset from the Resources folder

        string[] lines = fileData.text.Split(new char[] { '\n' });      //separate the text into lines

        for (int x = 1; x < lines.Length - 1; x++)                      //we skip the first line (headers)
        {
            string[] lineData = lines[x].Split(new char[] { ';' });     //we separate each data element or column

            NumInfo number = new NumInfo {
                num = int.Parse(lineData[0]), text = lineData[(int)LanguageSingleton.Instance.currentLanguage + 1]
            };                                                                                                                                   //we save the information at the nummeros list
            nummeros.Add(number);
        }

        return(nummeros);
    }
Exemple #13
0
 public void Push(int value)
 {
     if (!_cache.TryGetValue(value, out var info))
     {
         info = new NumInfo {
             Value = value
         };
         _cache.Add(value, info);
         _set.Add(info);
         if (_maxValue == null || value > _maxValue.Value)
         {
             _maxValue = info;
         }
         if (_minValue == null || value < _minValue.Value)
         {
             _minValue = info;
         }
     }
     info.Count++;
     _count++;
 }
Exemple #14
0
    public List <NumInfo> GetOptions(int numOptions)
    {
        List <NumInfo> options = new List <NumInfo>();

        //Generate random numbers different from current
        options.Add(currentNum); //we add the correct answer to make sure we do not reapet it
        while (options.Count < numOptions)
        {
            NumInfo n = GetRandomNumInfo();
            if (!options.Contains(n)) //We only add a number if it's not in the list
            {
                options.Add(n);
            }
        }
        options.RemoveAt(0); //remove the correct answer from the first position

        //Replace one random option with the correct number
        int randIndex = Random.Range(0, options.Count);

        options[randIndex] = currentNum;

        return(options);
    }
Exemple #15
0
 protected void bt_Clear_Click(object sender, EventArgs e)
 {
     lb_Operate.Text           = "";
     lb_Result.Text            = "0";
     ViewState["PreivousInfo"] = o_Num = null;
 }
Exemple #16
0
 public bool isCorrect(NumInfo numInfo)
 {
     return(numInfo.num == currentNum.num);
 }
Exemple #17
0
 public void Set(NumInfo info)
 {
     numInfo = info;
 }
Exemple #18
0
 public void DisplayNumber(NumInfo info)
 {
     view.Set(info);
     view.Display();
     view.Show(HideNumber);
 }