Example #1
0
        public static List <int> DeCateOriIntra(List <int> b, List <int> temp)
        {
            if (Floatz.ListIsZero(temp))
            {
                return new List <int> {
                           0
                }
            }
            ;
            temp = Floatz.ComprimaList(temp, "intreaga");
            if (Floatz.Compare2Lists(temp, b) == 1)
            {
                return new List <int> {
                           0
                }
            }
            ;
            if (Floatz.Compare2Lists(temp, b) == 0)
            {
                return new List <int> {
                           1
                }
            }
            ;


            List <int> _b = new List <int>();

            foreach (int item in b)
            {
                _b.Add(item);
            }

            List <int> i = new List <int> {
                0
            };
            int cmp = Floatz.Compare2Lists(temp, _b);

            while (cmp == -1)
            {
                i = Floatz.Add2Lists(i, new List <int> {
                    1
                });
                _b.Clear();
                _b  = Floatz.Multiply2Lists(b, i);
                cmp = Floatz.Compare2Lists(temp, _b);
            }
            if (cmp != 0)
            {
                i = Floatz.Subtract2Lists(i, new List <int> {
                    1
                });
            }
            i = ComprimaList(i);
            return(i);
        }
Example #2
0
        public static List <int> Subtract2Lists(List <int> refA, List <int> refB)
        {
            List <int> a = new List <int>();

            a.AddRange(refA);
            List <int> b = new List <int>();

            b.AddRange(refB);
            List <int> c = new List <int>();

            a.Reverse();
            b.Reverse();
            //a va fii lista cu cele mai multe numere
            if (a.Count < b.Count)
            {
                List <int> temp = a;
                a = b;
                b = temp;
            }
            int carry = 0;

            for (int i = 0; i < b.Count; i++)
            {
                int nr = a[i] - b[i] - carry;
                if (nr < 0)
                {
                    carry = 1;
                    nr   += 10;
                }
                else
                {
                    carry = 0;
                }
                c.Add(nr);
            }


            for (int i = b.Count; i < a.Count; i++)
            {
                c.Add(a[i] - carry);
                carry = 0;
            }


            c.Reverse();
            c = Floatz.ComprimaList(c);
            return(c);
        }