May 1, 2020 5:08 AM
| Last Modified: May 1, 2020 5:16 AM
This month’s challenge is back to basics – finding prime numbers.
I am interested in two functions:
getPrimes(n,t) – where n is a positive integer and t can be one of two values. If it is 1 getPrimes returns the first n primes. If it is 2 getPrimes will return all primes less than or equal to n. You can assume the value of n will not exceed 1e8.
isPrime(vec) – where vec is a nRow row, 1 column matrix of integer values no greater than 4e14. It is to return a matrix of 1’s and 0’s where vec[i] = 1 indicates the ith element of vec is prime and 0 it is not prime. The input test vector will contain between 100 and 1000 elements (but the function should be able to accepts larger or smaller vectors).
getPrimes(10,1) would return [2,3,5,7,11,13,17,19,23,29]
getPrimes(10,2) would return [2,3,5,7]
isPrime([-1,0,2,4,5]) would return [0,0,1,0,1]
Scoring: 4 points for each function. 3, 2, and 1 point for the fastest solution (awarded separately for each function). 3 points if your solution is as fast or faster than the fastest submitted by a staff member.
Submission deadline is Friday. May 15, 11:59 pm Eastern Time.