Lua Implementation of Problem 10

View source code here on GitHub!

Includes

Solution

solution()
Returns:

The solution to problem 10

Return type:

number

 1-- Project Euler Problem 10
 2--
 3-- Problem:
 4--
 5-- The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
 6--
 7-- Find the sum of all the primes below two million.
 8
 9local primes = loadlib("primes").primes
10
11return {
12    solution = function()
13        local answer = 0
14        local pg = primes(2000000)
15        local tmp = pg.next()
16
17        repeat
18            answer = answer + tmp
19            tmp = pg.next()
20        until not tmp
21
22        return answer;
23    end
24}

Tags: prime-number, lua-iterator