How do I get Prime numbers 1-100

How do I get prime numbers 1-100 ?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    My solution:

    Start with a few simple primes, such as local!primes:{2,3,5,7,13}

    forEach( items: enumerate(100) +1

    expression: if

    any(local!candidate = fv!item, /*any() function returns true if any of the elements in a boolean array are true*/

    forEach( items: local!primes)

    expression: mod(fv!candidate, fv!item) = 0 /*if a prime evenly divides your candidate number, it's not prime)

    true, /*true in this case means it's true that it's not prime*/

    false

    ), /*the for loop inside the any() function is just the first parameter of the if, if any are true, then it's not prime*/

    null, /*so if it's not prime, don't return it, or if none of the primes we picked out divide it, maybe it's prime, return it*/

    fv!item

    )

    Take the output of this and append it to local!primes to refine it.  You can keep adding more and more to get more and more primes.  It starts to get time consuming up into the 4 and 5 digit primes, but it will continue to work if you continue to add to the starting primes.

    You could also just go to wolfram alpha and copy and paste the answer into a constant.

Reply
  • 0
    Certified Lead Developer

    My solution:

    Start with a few simple primes, such as local!primes:{2,3,5,7,13}

    forEach( items: enumerate(100) +1

    expression: if

    any(local!candidate = fv!item, /*any() function returns true if any of the elements in a boolean array are true*/

    forEach( items: local!primes)

    expression: mod(fv!candidate, fv!item) = 0 /*if a prime evenly divides your candidate number, it's not prime)

    true, /*true in this case means it's true that it's not prime*/

    false

    ), /*the for loop inside the any() function is just the first parameter of the if, if any are true, then it's not prime*/

    null, /*so if it's not prime, don't return it, or if none of the primes we picked out divide it, maybe it's prime, return it*/

    fv!item

    )

    Take the output of this and append it to local!primes to refine it.  You can keep adding more and more to get more and more primes.  It starts to get time consuming up into the 4 and 5 digit primes, but it will continue to work if you continue to add to the starting primes.

    You could also just go to wolfram alpha and copy and paste the answer into a constant.

Children
No Data