예제 #1
0
        public void NumberIsPrime(string number, bool output)
        {
            PrimeFinder find   = new PrimeFinder();
            bool        actual = find.PrimeChecker(number);

            Assert.AreEqual(output, actual);
        }
예제 #2
0
        public void TestMultiple(int sequence, int expected)
        {
            PrimeFinder primetime = new PrimeFinder();
            int         prime     = primetime.GetPrime(sequence);

            Assert.Equal(expected, prime);
        }
예제 #3
0
        public override void Run()
        {
            PrimeFinder p = new PrimeFinder();

            p.CalcPrimesToNth(10010);
            Result = p[10001];
        }
예제 #4
0
        public void FindNthPrime_SecondPrime_Gets3()
        {
            PrimeFinder primeFinder = new PrimeFinder();

            Int64 result = primeFinder.FindNthPrime(2);

            Assert.AreEqual(3, result);
        }
예제 #5
0
        public void FindNthPrime_FirstPrime_Gets2()
        {
            PrimeFinder primeFinder = new PrimeFinder();

            Int64 result = primeFinder.FindNthPrime(1);

            Assert.AreEqual(2, result);
        }
예제 #6
0
        public void FindNthPrime_LargeIndexPrime_GetsResult()
        {
            PrimeFinder primeFinder = new PrimeFinder();

            Int64 result = primeFinder.FindNthPrime(50000);

            Assert.IsNotNull(result);
        }
예제 #7
0
        public void FindNthPrime_10000thPrime_GetsResult()
        {
            PrimeFinder primeFinder = new PrimeFinder();

            Int64 result = primeFinder.FindNthPrime(10000);

            Assert.AreEqual(104729, result);
        }
예제 #8
0
        public void FindNthPrime_FifthPrime_Gets11()
        {
            PrimeFinder primeFinder = new PrimeFinder();

            Int64 result = primeFinder.FindNthPrime(5);

            Assert.AreEqual(11, result);
        }
        /// <summary>
        /// Constructs a matrix with a given number of slices, rows and columns using memory as specified.
        /// All entries are initially <i>0</i>.
        /// For details related to memory usage see {@link cern.colt.map.OpenIntDoubleHashMap}.
        ///
        /// @param slices the number of slices the matrix shall have.
        /// @param rows the number of rows the matrix shall have.
        /// @param columns the number of columns the matrix shall have.
        /// @param initialCapacity   the initial capacity of the hash map.
        ///                          If not known, set <i>initialCapacity=0</i> or smalld
        /// @param minLoadFactor        the minimum load factor of the hash map.
        /// @param maxLoadFactor        the maximum load factor of the hash map.
        /// @throws	ArgumentException if <i>initialCapacity < 0 || (minLoadFactor < 0.0 || minLoadFactor >= 1.0) || (maxLoadFactor <= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >= maxLoadFactor)</i>.
        /// @throws	ArgumentException if <i>(double)columns*rows > int.MaxValue</i>.
        /// @throws	ArgumentException if <i>slices<0 || rows<0 || columns<0</i>.
        /// </summary>
        /// <summary>
        ///
        /// </summary>
        /// <param name="slices"></param>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <param name="initialCapacity"></param>
        /// <param name="minLoadFactor"></param>
        /// <param name="maxLoadFactor"></param>
        /// <exception cref=""></exception>
        /// <exception cref=""></exception>
        /// <exception cref=""></exception>
        public SparseDoubleMatrix3D(int slices, int rows, int columns, int initialCapacity, double minLoadFactor, double maxLoadFactor)
        {
            Setup(slices, rows, columns);
            this.MinLoadFactor = minLoadFactor;
            this.MaxLoadFactor = maxLoadFactor;

            var capacity = PrimeFinder.NextPrime(initialCapacity);

            this.Elements = new Dictionary <int, Double>(capacity);
        }
예제 #10
0
        public static void Main()
        {
            Console.Write("Enter a number and I'll find all prime numbers up to that number: ");
            int        response  = int.Parse(Console.ReadLine());
            List <int> primeList = PrimeFinder.PrimeFunction(response);

            foreach (int num in primeList)
            {
                Console.Write(num + " ");
            }
        }
예제 #11
0
        public void TestFindPrimeNumbers(int n, int[] expectedPrimes)
        {
            var primeFinder = new PrimeFinder();
            var primes      = primeFinder.FindPrimeNumbersLessThanOrEqualTo(n).ToArray();

            Assert.AreEqual(expectedPrimes.Length, primes.Length);
            for (int i = 0; i < primes.Length; i++)
            {
                Assert.AreEqual(expectedPrimes[i], primes[i]);
            }
        }
        /// <summary>
        /// Constructs a matrix with a given number of parameters.
        /// All entries are initially <i>null</i>.
        /// For details related to memory usage see {@link cern.colt.map.OpenIntObjectHashMap}.
        /// </summary>
        /// <param name="size">the number of cells the matrix shall have.</param>
        /// <param name="initialCapacity">the initial capacity of the hash map.  If not known, set <i>initialCapacity=0</i> or smalld  </param>
        /// <param name="minLoadFactor">the minimum load factor of the hash map.</param>
        /// <param name="maxLoadFactor">the maximum load factor of the hash map.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">if <i>initialCapacity &lt; 0 || (minLoadFactor &lt; 0.0 || minLoadFactor >= 1.0) || (maxLoadFactor &lt;= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >= maxLoadFactor)</i>.</exception>
        /// <exception cref="ArgumentException">if <i>size &lt; 0</i>.</exception>
        public SparseObjectMatrix1D(int size, int initialCapacity, double minLoadFactor, double maxLoadFactor)
        {
            Setup(size);
            //this.Elements = new OpenIntObjectHashMap(initialCapacity, minLoadFactor, maxLoadFactor);
            this.MinLoadFactor = minLoadFactor;
            this.MaxLoadFactor = maxLoadFactor;

            var capacity = PrimeFinder.NextPrime(initialCapacity);

            this.Elements = new Dictionary <int, Object>(capacity);
        }
예제 #13
0
 public IdManager(string name, uint firstId, uint lastId, string[,] objTables, uint[] exclude,
                  bool distinct = false)
 {
     _name       = name;
     _firstId    = firstId;
     _lastId     = lastId;
     _objTables  = objTables;
     _exclude    = exclude;
     _distinct   = distinct;
     _freeIdSize = (int)(_lastId - _firstId);
     PrimeFinder.Init();
 }
예제 #14
0
        private void IncreaseBitSetCapacity(int count)
        {
            var size = PrimeFinder.NextPrime(count);

            if (size > _freeIdSize)
            {
                size = _freeIdSize;
            }
            var newBitSet = new BitSet(size);

            newBitSet.Or(_freeIds);
            _freeIds = newBitSet;
        }
예제 #15
0
 public ActionResult NextPrime(PrimeSearchTool number)
 {
     if (ModelState.IsValid)
     {
         var primeFinder = new PrimeFinder();
         var primer      = new Primer();
         primer.StartNumber = number.FirstNumber.Value;
         primer             = primeFinder.FindPrime(primer);
         number.NextPrime   = primer.PrimeNumber;
         return(View("NextPrime", number));
     }
     return(View("NextPrime", number));
 }
예제 #16
0
        static void Main(string[] args)
        {
            //BigInteger rsa_modul = BigInteger.Parse(RSA_MODUL);
            //BigInteger root = BigInteger.Parse("1000");
            //for (int i = 0; i < 50; i++) {
            //    root = ((rsa_modul / root) + root) / 2;
            //    Console.WriteLine("Estimated root of RSA modul: " + root);
            //}
            PrimeFinder finder = new PrimeFinder(BigInteger.Parse(RSA_MODUL_ROOT_GUESS));

            finder.Run();
            Console.ReadKey(true);
        }
예제 #17
0
        static void Main(string[] args)
        {
            //Problem P = new Problem007();
            //P.Setup();
            //P.Run();
            //Console.WriteLine(P.GetResultString());
            StreamReader r = new StreamReader(new FileStream("C:/"))
                             PrimeFinder P = new PrimeFinder();

            P.CalcPrimesToNth(10010);
            int myPrime, realPrime;

            for (int i = 0; i < P.Count; i++)
            {
                myPrime = P[i];
            }
        }
예제 #18
0
        static void Main(string[] args)
        {
            BlackBoard blackBoard = new BlackBoard();

            ControlData data1 = new ControlData("PrimeNumbers", new object[] { 100 });

            blackBoard.update("DAT0001", data1);

            PrimeFinder primeFinder = new PrimeFinder();

            blackBoard.addKnowledgeWorker(primeFinder);

            blackBoard.print();
            blackBoard.control.loop();
            blackBoard.print();
            System.Console.ReadKey();
        }
예제 #19
0
        public bool Initialize()
        {
            try
            {
                _freeIds = new BitSet(PrimeFinder.NextPrime(100000));
                _freeIds.Clear();
                _freeIdCount = _freeIdSize;

                foreach (var usedObjectId in ExtractUsedObjectIdTable())
                {
                    if (_exclude.Contains(usedObjectId))
                    {
                        continue;
                    }
                    var objectId = (int)(usedObjectId - _firstId);
                    if (usedObjectId < _firstId)
                    {
                        _log.Warn("{0}: Object ID {1} in DB is less than {2}", _name, usedObjectId, _firstId);
                        continue;
                    }

                    if (objectId >= _freeIds.Count)
                    {
                        IncreaseBitSetCapacity(objectId + 1);
                    }
                    _freeIds.Set(objectId);
                    Interlocked.Decrement(ref _freeIdCount);
                }

                _nextFreeId = _freeIds.NextClear(0);
                _log.Info("{0} successfully initialized", _name);
            }
            catch (Exception e)
            {
                _log.Error("{0} could not be initialized correctly", _name);
                _log.Error(e);
                return(false);
            }

            return(true);
        }
 public void Setup()
 {
     primeFinder = new PrimeFinder();
     expected    = new List <Int32>();
 }
 /// <summary>
 /// Chooses a new prime table capacity optimized for shrinking that (approximately) satisfies the invariant
 /// c * minLoadFactor &lt;= size &lt;= c * maxLoadFactor
 /// and has at least one FREE slot for the given size.
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="dic"></param>
 /// <param name="size"></param>
 /// <param name="minLoad"></param>
 /// <param name="maxLoad"></param>
 /// <returns></returns>
 public static int ChooseShrinkCapacity <TKey, TValue>(this IDictionary <TKey, TValue> dic, int size, double minLoad, double maxLoad)
 {
     return(PrimeFinder.NextPrime(System.Math.Max(size + 1, (int)((4 * size / (minLoad + 3 * maxLoad))))));
 }