public void TrialDivLargerKnown()
 {
     IPrimes p = new PrimesTrialDivision();
       Assert.AreEqual(541, p[99]);
       Assert.AreEqual(7919, p[999]);
       Assert.AreEqual(104729, p[9999]);
 }
 public void TrialDivSmall()
 {
     IPrimes p = new PrimesTrialDivision();
       Assert.AreEqual(2, p[0]);
       Assert.AreEqual(3, p[1]);
       Assert.AreEqual(5, p[2]);
       Assert.AreEqual(7, p[3]);
       Assert.AreEqual(11, p[4]);
       Assert.AreEqual(13, p[5]);
       Assert.AreEqual(17, p[6]);
       Assert.AreEqual(19, p[7]);
 }
Ejemplo n.º 3
0
        private static void Main_MayThrow(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());

              CommandLineParser clp = new CommandLineParser(args);
              string primesFile = clp.OptionValue(OptionName.PrimesFile, "primes.bin");
              string sPrimesLimit = clp.OptionValue(OptionName.PrimesLimit, "");
              string adbName = clp.OptionValue(OptionName.AdbFile, "aliquot.adb");
              string sDbLimit = clp.OptionValue(OptionName.AdbLimit, "100000");

              if (clp.HasOption(OptionName.MakePrimes))
              {
            if (!WarnOfLongOperationAndCheckIfUserWantsToContinue(string.Format("create primes file {0}", primesFile), 3.5))
            {
              return;
            }
            MakePrimesFile(primesFile, sPrimesLimit);
              }

              if(clp.HasOption(OptionName.MakeAdb))
              {
            if (!WarnOfLongOperationAndCheckIfUserWantsToContinue(string.Format("create aliquot DB {0}", adbName), 40.0))
            {
              return;
            }
            MakeAdbFile(primesFile, adbName, sDbLimit);
              }

              if (clp.HasOption(OptionName.Init))
              {
            if (!WarnOfLongOperationAndCheckIfUserWantsToContinue(string.Format("create primes file {0} and aliquot DB {1}", primesFile, adbName), 43.5))
            {
              return;
            }

            Console.Out.WriteLine("Creating primes (-makeprimes)");
            MakePrimesFile(primesFile);

            Console.Out.WriteLine("Creating ADB (-makeadb)");
            MakeAdbFile(primesFile, adbName, sDbLimit);

            Console.Out.WriteLine("Initialisation Complete.");
              }

              if (clp.HasOption(OptionName.ShowAdb))
              {
            var db = AliquotDatabase.Open(adbName);
            db = null;
              }

              if(clp.HasOption(OptionName.GvTree))
              {
            string gvOut = clp.OptionValue(OptionName.GvOut, "stdout");
            BigInteger treeBase = BigInteger.Parse(clp.OptionValue(OptionName.GvTree, "3"));
            WriteGvTree(gvOut, adbName, treeBase, sDbLimit);
              }

              if(clp.HasOption(OptionName.ExportTable))
              {
            ExportTable(adbName, "2", sDbLimit);
              }

              if(clp.HasOption(OptionName.GvFindDot))
              {
            GraphViz.FindDotExe(GraphViz.GetUserInput_Int32_Console);
              }

              if(clp.OptionValues.Count == 0)
              {
            string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            string assemblyVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            Console.Out.WriteLine("{0} {1}", assemblyName, assemblyVersion);
            Console.Out.WriteLine("");
            Console.Out.WriteLine("Routines to investigate Aliquot Sequences");
            Console.Out.WriteLine("");
            Console.Out.WriteLine("Switches:");
            Console.Out.WriteLine("-AdbFile=FILENAME      ... name of ADB file (default aliquot.adb)");
            Console.Out.WriteLine("-AdbLimit=MAXTOPROCESS ... Highest number to look at (default 100000)");
            Console.Out.WriteLine("-ExportTable           ... write table of numbers in ADB");
            Console.Out.WriteLine("-GvFindDot             ... discover dot.exe");
            Console.Out.WriteLine("-GvTree=TREEBASE       ... make Gv tree (default 3)");
            Console.Out.WriteLine("-GvOut                 ... set output file for Gv functions");
            Console.Out.WriteLine("-Init                  ... create all initial setup");
            Console.Out.WriteLine("-MakeAdb               ... create ADB file");
            Console.Out.WriteLine("-MakePrimes            ... create Primes file");
            Console.Out.WriteLine("-PrimesFile=FILENAME   ... name of Primes file (default primes.bin)");
            Console.Out.WriteLine("-ShowAdb               ... dump details of ADB file");
              }
            #if false
              var ptd = new PrimesTrialDivision();
              var db = AliquotDatabase.Create(ptd, 100); // 100000
              db.SaveAs("aliquot100.adb");
              var db2 = AliquotDatabase.Open("aliquot100.adb");
              // db.ShowTree(3, 1000);
              return;
            #endif
        }