December 2015
Beginner
442 pages
10h 12m
English
Before we finish off this chapter, how about a final example? I was thinking we could write a function to generate a list of prime numbers up to a limit. We've already seen the code for this so let's make it a function and, to keep it interesting, let's optimize it a bit.
It turns out that you don't need to divide it by all numbers from 2 to N-1 to decide if a number N is prime. You can stop at
. Moreover, you don't need to test the division for all numbers from 2 to
, you can just use the primes in that range. I'll leave it to you ...
Read now
Unlock full access