![]() ![]() The things that I didn’t get right in my first go round: I’m still lacking a true understanding of how to generate prime numbers efficiently. I initially hadn’t been too far away from getting the solution, just needed a bit of tidying up. So I went back to the brute force, which took many minutes. I tried to avoid doing that, using various methods I’d already been using in earlier ones, trying to apply the Sieve of Eratosthenes, stepping in sixes, etc but with no luck. A slightly less brute method would be to do it in steps of 2, avoiding the even numbers (except 2). The brute force way to do this would be to loop from 1-2000000, checking if each number is prime before adding it to your total. ![]() The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.įind the sum of all the primes below two million. In the end I used something that took ages to run, and decided to refactor my code once I’d read some of the discussions you get access to after completing these problems. The code isn’t that difficult, but making something that can run efficiently on my old CF 5 server seemed a bit trickier.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |