public static void Test()
 {
     DisplayResults.Display(IsPrime(1));
     DisplayResults.Display(IsPrime(0));
     DisplayResults.Display(IsPrime(-1));
     DisplayResults.Display(IsPrime(2));
     DisplayResults.Display(IsPrime(3));
     DisplayResults.Display(IsPrime(4));
     DisplayResults.Display(IsPrime(5));
     DisplayResults.Display(IsPrime(6));
     DisplayResults.Display(IsPrime(101));
 }
Пример #2
0
        /*the below is slow.*/

        /*public static ulong[] productFib(ulong prod)
         * {
         *  ulong num = 0;
         *  ulong resultN = 0;
         *  ulong resultNP = 0;
         *  while (resultN * resultNP < prod)
         *  {
         *      num++;
         *      resultN = Fibonacci(num);
         *      resultNP = Fibonacci(num + 1);
         *  }
         *  if (resultN * resultNP == prod)
         *      return new ulong[] { resultN, resultNP, 1 };
         *  else
         *      return new ulong[] { resultN, resultNP, 0 };
         *  //return new ulong[] { resultN-(num * 2 - 3), resultNP - ((num+1) * 2 - 3), 0 };
         * }
         *
         * public static ulong Fibonacci(ulong n)
         * {
         *  if (n <= 2)
         *  {
         *      return 1;
         *  }
         *  return Fibonacci(n - 1) + Fibonacci(n - 2);
         * }*/

        public static void Test()
        {
            DisplayResults.Display(productFib(0));
            DisplayResults.Display(productFib(1));
            DisplayResults.Display(productFib(2));
            DisplayResults.Display(productFib(3));
            DisplayResults.Display(productFib(4));
            DisplayResults.Display(productFib(5));
            DisplayResults.Display(productFib(714));
            DisplayResults.Display(productFib(800));
            DisplayResults.Display(productFib(4895));
        }
        /*public static List<int> DynamicArray(int n, List<List<int>> queries)
         *  {
         *  List<int> seqList = new List<int>(n);
         *  List<int> s0 = new List<int>();
         *  List<int> s1 = new List<int>();
         *  int lastAnswer = 0;
         *  foreach(var query in queries)
         *  {
         *      int qn = query[0];
         *      int x = query[1];
         *      int y = query[2];
         *      int seq = (x ^ lastAnswer) % n;
         *      if(qn == 1)
         *      {
         *          if(seq == 0)
         *          {
         *              s0.Add(y);
         *          }
         *          if(seq == 1)
         *          {
         *              s1.Add(y);
         *          }
         *      }
         *      else if(qn == 2)
         *      {
         *          if(seq == 0)
         *          {
         *              lastAnswer = s0[s0.Count-1];
         *          }
         *          if(seq == 1)
         *          {
         *              lastAnswer = s1[s1.Count-1];
         *          }
         *          seqList.Add(lastAnswer);
         *      }
         *  }
         *  return seqList;
         * }*/

        public static void Test()
        {
            int sample = 2;
            List <List <int> > queries = new List <List <int> >();

            queries.Add(new List <int> {
                1, 0, 5
            });
            queries.Add(new List <int> {
                1, 1, 7
            });
            queries.Add(new List <int> {
                1, 0, 3
            });
            queries.Add(new List <int> {
                2, 1, 0
            });
            queries.Add(new List <int> {
                2, 1, 1
            });
            DisplayResults.Display(DynamicArray(sample, queries));
        }
Пример #4
0
        public static void Test()
        {
            int[][] array =
            {
                new [] { 1, 2, 3 },
                new [] { 4, 5, 6 },
                new [] { 7, 8, 9 }
            };
            DisplayResults.Display(Snail(array));

            int[][] array2 =
            {
                new [] {  1,  2,  3, 4 },
                new [] { 12, 13, 14, 5 },
                new [] { 11, 16, 15, 6 },
                new [] { 10,  9,  8, 7 }
            };
            DisplayResults.Display(Snail(array2));

            int[][] array3 = { new int[] { } };
            DisplayResults.Display(Snail(array3));
        }
        /*public static long hamming(int n)
         * {
         *  int i = 0, j = 0, k = 0;
         *  List<long> result = new List<long>();
         *  HashSet<long> result2 = new HashSet<long>();
         *  for (k = 0; k <= n / 5 + 1; k++)
         *  {
         *      for (j = 0; j <= n / 3 + 1; j++)
         *      {
         *          for (i = 0; i <= n / 2 + 1; i++)
         *          {
         *              if ((long)Math.Pow(2, i) * (long)Math.Pow(3, j) * (long)Math.Pow(5, k) > 0)
         *                  result.Add((long)Math.Pow(2, i) * (long)Math.Pow(3, j) * (long)Math.Pow(5, k));
         *          }
         *      }
         *  }
         *  result.Sort();
         *  return result[n - 1];
         * }*/
        public static long hamming(int n)
        {
            int         i = 0, j = 0, k = 0;
            List <long> result = new List <long>();

            for (k = 0; k <= 2; k++)
            {
                for (j = 0; j <= 2; j++)
                {
                    for (i = 0; i <= 5; i++)
                    {
                        if ((long)Math.Pow(2, i) * (long)Math.Pow(3, j) * (long)Math.Pow(5, k) > 0)
                        {
                            result.Add((long)Math.Pow(2, i) * (long)Math.Pow(3, j) * (long)Math.Pow(5, k));
                        }
                    }
                }
            }
            result.Sort();
            DisplayResults.Display(result);
            long[] set   = new long[5];
            int    index = 0;

            for (int s = 7; s <= 26; s++)
            {
                set[index++] = result[s - 1];
            }
            if (n > 6)
            {
                int setCoefficient = ((n - 7) / 28) + 1;
                int setIndex       = (n - 28) % 5;
                return(set[setIndex] * (long)Math.Pow(2, setCoefficient - 1));
            }
            else
            {
                return(result[n - 1]);
            }
        }
Пример #6
0
        public static void Test()
        {
            List <long[]> tmp = removNb(26);

            foreach (long[] x in tmp)
            {
                DisplayResults.Display(x);
            }

            List <long[]> tmp2 = removNb(1000003);

            foreach (long[] x in tmp2)
            {
                DisplayResults.Display(x);
            }

            List <long[]> tmp3 = removNb(846);

            foreach (long[] x in tmp3)
            {
                DisplayResults.Display(x);
            }
        }
 public static void Test()
 {
     DisplayResults.Display(SortArray(new int[] { 5, 3, 2, 8, 1, 4 }));
     DisplayResults.Display(SortArray(new int[] { 5, 3, 1, 8, 0 }));
     DisplayResults.Display(SortArray(new int[] { }));
 }
Пример #8
0
 public void Test()
 {
     DisplayResults.Display(ProcessQueries(new int[] { 3, 1, 2, 1 }, 5));
     DisplayResults.Display(ProcessQueries(new int[] { 4, 1, 2, 2 }, 4));
     DisplayResults.Display(ProcessQueries(new int[] { 7, 5, 5, 8, 3 }, 8));
 }
 public static void Test()
 {
     DisplayResults.Display(Rgb(255, 255, 255));
     DisplayResults.Display(Rgb(255, 255, 300));
 }
 public static void Test()
 {
     DisplayResults.Display(MoveZeroes(new int[] { 1, 2, 0, 1, 0, 1, 0, 3, 0, 1 }));
 }
 public static void Test()
 {
     object[] sample = new object[] { 1, 2, 3, 4, 5, 6, 7 };
     DisplayResults.Display(JosephusPermutation(new List <object>(sample), 3));
 }
 public static void Test()
 {
     DisplayResults.Display(SongDecoder("WUBWUBABCWUB"));
     DisplayResults.Display(SongDecoder("RWUBWUBWUBLWUB"));
 }
 public void Test()
 {
     string[] sample1 = new string[] { "mass", "as", "hero", "superhero" };
     DisplayResults.Display(StringMatching(sample1));
 }
 public static void Test()
 {
     DisplayResults.Display(FindShort("bitcoin take over the world maybe who knows perhaps"));
     DisplayResults.Display(FindShort("turns out random test cases are easier than writing out basic ones"));
 }
 public static void Test()
 {
     DisplayResults.Display(wave("hello"));
     DisplayResults.Display(wave("two words"));
 }