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:
def isPrime(n)
n > 1 and (2..Math.sqrt(n)).find{ i n % i == 0 }.nil?
end
Testing:
isPrime(1)
=> false
isPrime(2)
=> true
isPrime(3)
=> true
isPrime(4)
=> false
isPrime(3571)
=> true
References
Noah Kindler from video http://vimeo.com/79718197 , his blog: http://www.codewod.com/
Recommended reading

Find the missing element in a randomized range of numbers
I take n consecutive integers, toss one of them out and mix up the remaining n1 integers as completely unsorted. Find the missing integer.

Time Complexity of ArrayList Insertion
Then calculate the average time complexity of inserting n new items into an empty brand new ArrayList.

Find the odd ball among eight balls
You are given eight balls that look exactly the same, and a balance to weigh them against each other. Find the odd ball by weighing only twice?

Getting paid for seven days with a single bar of gold
An employer hires you to work for 7 days and has a gold bar with 7 segments to pay you with. How do you get them to not break it to pieces?
 Author
 Amin Ariana
 Published
 November 2013