cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

JMP Challenge

Challenges that focus on the JMP Scripting Language and occasionally, some that can be done without scripting.
Choose Language Hide Translation Bar
Challenge 2

jmp-challenge-v2.pngThis month’s challenge is back to basics – finding prime numbers.

I am interested in two functions:

  1. 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.
  2. 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).

Examples:

   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.

Last Modified: Dec 21, 2023 1:13 PM
Comments