Return true if input is a Prime number

You are given n, a positive integer. Return true if n is a prime number, and false if it's not.


Problem Statement

You are given n, a positive integer. Return true if n is a prime number, and false if it's not.


Evaluation


  • Correct idea: 25%

  • Answer with no bugs: 25%

  • Square Root optimization: 25%

  • Memoization suggestion: 25%


Solution

My one liner solution in Ruby without memoization:

Testing:


References

Asked by Noah Kindler. Video http://vimeo.com/79718197 , his blog: http://www.codewod.com/ .

Amin A.

Written by

Amin Ariana

A software entrepreneur from San Francisco