예제 #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);
        }
예제 #2
0
            public static string TestDeCateOriIntra()
            {
                object[,] teste = new object[, ] {
                    { "0", "0", "0" },
                    { "1", "1", "1" },
                    { "1", "2", "2" },
                    { "1", "3", "3" },
                    { "2", "4", "2" },
                    { "6", "12", "2" },
                    { "24", "12", "0" },
                    { "113", "355", "3" },
                    { "456", "1368", "3" },
                    { "74916", "674244", "9" },
                    { "44", "1242", "28" },
                    { "51", "500", "9" }
                };

                string str = "";

                for (int i = 0; i < teste.GetLength(0); i++)
                {
                    List <int> b = new List <int>();

                    for (int j = 0; j < ((string)teste[i, 0]).Length; j++)
                    {
                        b.Add(Floatz.charToInt(((string)teste[i, 0])[j]));
                    }

                    List <int> temp = new List <int>();
                    for (int j = 0; j < ((string)teste[i, 1]).Length; j++)
                    {
                        temp.Add(Floatz.charToInt(((string)teste[i, 1])[j]));
                    }
                    List <int> resultCorrect = new List <int>();
                    for (int j = 0; j < ((string)teste[i, 2]).Length; j++)
                    {
                        resultCorrect.Add(Floatz.charToInt(((string)teste[i, 2])[j]));
                    }

                    List <int> result = Floatz.DeCateOriIntra(b, temp);
                    if (Floatz.Compare2Lists(result, resultCorrect) != 0)
                    {
                        str += String.Format(
                            "\n Test failed:DeCateOriIntra #{0} nereusita.\n \n b={1},temp={2}, result={3} |corect e: {4}\n\n",
                            i, Floatz.ListToString(b), Floatz.ListToString(temp), Floatz.ListToString(result), Floatz.ListToString(resultCorrect)
                            );
                    }
                }
                if (str == "")
                {
                    return("Nu exista probleme la DeCateOriIntra.");
                }
                return(str);
            }