Ejemplo n.º 1
0
        //I added <summaries> because I get confused which one is which :P

        /// <summary>
        /// This will convert our input into our custom base format.
        /// </summary>
        /// <param name="input">The input will be assumed to be an IntX number. Or else this will return null.</param>
        /// <param name="baseAlpha">The custom alphabet for conversion</param>
        /// <returns>Null if input was improperly formatted. Else, returns the converted output string.</returns>
        public string convertToBase(string input, char[] baseAlpha)
        {
#if (SHOW_TIME)
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif

            try
            {
                IntX          x          = IntX.Parse(input); //We'll deal with ridiculously large numbers
                StringBuilder sb         = new StringBuilder();
                int           targetBase = baseAlpha.Length;
                do
                {
                    sb.Append(baseAlpha[(int)(x % targetBase)]);
                    x /= targetBase;
                } while (x > 0);
                char[] garbage = sb.ToString().ToCharArray();
                Array.Reverse(garbage);
#if (SHOW_TIME)
                sw.Stop();
                Debug.WriteLine("Time elapsed: " + sw.ElapsedMilliseconds + " ms");
#endif
                return(new string(garbage));
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected IntX parse format! (" + e.Message + ")");
                return(null);
            }
        }
Ejemplo n.º 2
0
        public void Sign()
        {
            IntX int1 = IntX.Parse("-7");

            Assert.IsTrue(int1 == -7);
            int1 = IntX.Parse("+7");
            Assert.IsTrue(int1 == 7);
        }
Ejemplo n.º 3
0
 public static FractionX FromString(string str)
 {
     if (str.Contains('/'))
     {
         int index = str.IndexOf('/');
         return(new FractionX(IntX.Parse(str.Substring(0, index)), IntX.Parse(str.Substring(index + 1))));
     }
     return(new FractionX(IntX.Parse(str)));
 }
Ejemplo n.º 4
0
        public void CompareWithClassicRandom()
        {
            TestHelper.Repeat(
                RandomRepeatCount,
                delegate
            {
                string str   = GetRandomChars();
                IntX classic = IntX.Parse(str, ParseMode.Classic);
                IntX fast    = IntX.Parse(str, ParseMode.Fast);

                Assert.IsTrue(classic == fast);
            });
        }
Ejemplo n.º 5
0
        public void CompareWithClassic()
        {
            TestHelper.Repeat(
                RepeatCount,
                delegate
            {
                string str   = GetAllNineChars(_length);
                IntX classic = IntX.Parse(str, ParseMode.Classic);
                IntX fast    = IntX.Parse(str, ParseMode.Fast);

                Assert.IsTrue(classic == fast);

                _length += LengthIncrement;
            });
        }
Ejemplo n.º 6
0
        public void CompareWithClassicRandom()
        {
            TestHelper.Repeat(
                RandomRepeatCount,
                delegate
            {
                string str = GetRandomChars();
                IntX x     = IntX.Parse(str, ParseMode.Fast);

                x.Settings.ToStringMode = ToStringMode.Fast;
                string strFast          = x.ToString();
                x.Settings.ToStringMode = ToStringMode.Classic;
                string strClassic       = x.ToString();

                Assert.AreEqual(str, strFast);
                Assert.AreEqual(strFast, strClassic);
            });
        }
Ejemplo n.º 7
0
        public void Base()
        {
            IntX int1 = IntX.Parse("abcdef", 16);

            Assert.IsTrue(int1 == 0xabcdef);
            int1 = IntX.Parse("100", 8);
            Assert.IsTrue(int1 == 64);
            int1 = IntX.Parse("0100");
            Assert.IsTrue(int1 == 64);
            int1 = IntX.Parse("0100000000000");
            Assert.IsTrue(int1 == 0x200000000UL);
            int1 = IntX.Parse("0xabcdef");
            Assert.IsTrue(int1 == 0xabcdef);
            int1 = IntX.Parse("0XABCDEF");
            Assert.IsTrue(int1 == 0xabcdef);
            int1 = IntX.Parse("020000000000");
            Assert.IsTrue(int1 == 0x80000000);
        }
Ejemplo n.º 8
0
        public void CompareWithClassic()
        {
            TestHelper.Repeat(
                RepeatCount,
                delegate
            {
                string str = GetAllNineChars(_length);
                IntX x     = IntX.Parse(str, ParseMode.Fast);

                x.Settings.ToStringMode = ToStringMode.Fast;
                string strFast          = x.ToString();
                x.Settings.ToStringMode = ToStringMode.Classic;
                string strClassic       = x.ToString();

                Assert.AreEqual(str, strFast);
                Assert.AreEqual(strFast, strClassic);

                _length += LengthIncrement;
            });
        }
Ejemplo n.º 9
0
    static void Main(string[] args)
    {
        try
        {
            using (StreamReader sr = new StreamReader(args[0]))
                using (StreamWriter sw = new StreamWriter(args[1]))
                {
                    long t = long.Parse(sr.ReadLine().Trim());
                    for (int i = 0; i < t; ++i)
                    {
                        // get values
                        string[] strs = sr.ReadLine().Trim().Split(' ');
                        long     n    = int.Parse(strs[0]);

                        IntX[] values = new IntX[n];
                        for (int j = 0; j < n; ++j)
                        {
                            values[j] = IntX.Parse(strs[j + 1]);
                        }
                        Array.Sort(values);

                        IntX common = values[1] - values[0];
                        for (int j = 2; j < n; ++j)
                        {
                            common = gcj(common, values[j] - values[j - 1]);
                        }

                        IntX val = common - values[0] % common;

                        string line = "Case #" + (i + 1) + ": " + (val % common);

                        Console.WriteLine(line);
                        sw.WriteLine(line);
                    }
                }
        }
        catch (Exception e) { Console.WriteLine(e.Message + e.StackTrace); }
        Console.WriteLine("press any key to quit");
        Console.ReadKey();
    }
Ejemplo n.º 10
0
 public void InvalidFormat2()
 {
     IntX.Parse("abc");
 }
Ejemplo n.º 11
0
 public void InvalidFormat()
 {
     IntX.Parse("-123-");
 }
Ejemplo n.º 12
0
 public void Parse()
 {
     Assert.AreEqual(19 * 20 + 18, (int)IntX.Parse("JI", 20, "0123456789ABCDEFGHIJ"));
 }
Ejemplo n.º 13
0
 public void AlphabetNull()
 {
     IntX.Parse("", 20, null);
 }
Ejemplo n.º 14
0
 public void AlphabetShort()
 {
     IntX.Parse("", 20, "1234");
 }
Ejemplo n.º 15
0
 public void AlphabetRepeatingChars()
 {
     IntX.Parse("", 20, "0123456789ABCDEFGHIJ0");
 }
Ejemplo n.º 16
0
 public void Null()
 {
     IntX.Parse(null);
 }
Ejemplo n.º 17
0
        public void WhiteSpace()
        {
            IntX int1 = IntX.Parse("  7 ");

            Assert.IsTrue(int1 == 7);
        }
Ejemplo n.º 18
0
        public void Zero()
        {
            IntX int1 = IntX.Parse("0");

            Assert.IsTrue(int1 == 0);
        }
Ejemplo n.º 19
0
        public void BigDec()
        {
            IntX intX = IntX.Parse("34589238954389567586547689234723587070897800300450823748275895896384753238944985");

            Assert.AreEqual(intX.ToString(), "34589238954389567586547689234723587070897800300450823748275895896384753238944985");
        }
Ejemplo n.º 20
0
 public void InvalidFormat3()
 {
     IntX.Parse("987", 2);
 }