solve for prime

Warren HansenUncategorizedLeave a Comment

A friend of mine was administering a whiteboard test to a prospective hire. He asked what he thought was a straightforward question. Can you write a function to solve for prime? The young lion fumbled around and offered that he thought there was a pre-defined one function from .Net. He never produced a working function and was never hired.


This made me think about how well I might do in the same situation. I think I would do a fair bit of fumbling so I decided to write my own function ahead of time… write it down on a piece of paper… then quickly tear it up so no one would know….
I encourage you to think this over between cute dog videos on youtube and come up with your own answer. Here is the definition from Google in case you need a refresher.

prime number is a whole number greater than 1, whose only two whole-number factors are 1 and itself. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29. As we proceed in the set of natural numbers N = {1, 2, 3, …}, the primes become less and less frequent in general.

I decided to out myself here and show my work. Maybe you will face this age old question some day but here is what I came up with.

 

Console Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.