Re: interview question on primes



Got this on a software engineering interview
question:
given two integers A and B, find all primes between
them.

I basically wrote an initial function, bool
isPrime(int i), which
loops over all numbers between 2 and sqrt(i) to see
if i%num == 0,
in which case the number is not a prime. With this
function, I then
loop between A and B, calling isPrime() on each
value.

Any better ideas?


I'm curious about 2 things:

1. What was the interviewer's response to your solution ?

2. What type of software job were you interviewing for ?

I spent many years as a so-called software engineer in the financial world, and never once had to find a prime number.
.



Relevant Pages

  • Re: True inconsistency in Python
    ... >> he added bool, True, and False, but he wouldn't listen... ... 1000 loops, best of 3: 1.26e+03 usec per loop ... bounded your performance loss to 30-50% when compared to the simplest ...
    (comp.lang.python)
  • Re: Testing for an empty dictionary in Python
    ... object of type 'bool' has no len ... I presume you meant ... is expensive for large dictionaries, ... I don't understand "makes loops O" ... ...
    (comp.lang.python)