public void GetPrimesFactors_13195_ReturnsExpectedList() { // Arrange var number = 13195; var expectedResult = new List <long> { 5, 7, 13, 29 }; // Act var result = PrimeHelper.GetPrimeFactors(number); // Assert result.Should().BeEquivalentTo(expectedResult); }
static void Main(string[] args) { int countOfItems = 1000; ConcurrentQueue <int> queue = new ConcurrentQueue <int>(); Task producer = Task.Factory.StartNew( () => { Random r = new Random(); for (int i = 0; i < countOfItems; i++) { queue.Enqueue(r.Next(1000000)); } } ); Task consumer = Task.Factory.StartNew( () => { for (int i = 0; i < countOfItems;) { int number; if (queue.TryDequeue(out number)) { List <int> factors = PrimeHelper.GetPrimeFactors(number); Console.WriteLine("{0} = {1}", number, string.Join("*", PrimeHelper.GetPrimeFactors(number)) ); i++; } } } ); Task.WaitAll(producer, consumer); }
public long ComputeSolution() { var primeFactorsOfNumber = PrimeHelper.GetPrimeFactors(NUMBER_TO_FACTOR_INTO_PRIMES); return(primeFactorsOfNumber.Max()); }