Lua Implementation of Problem 7

View source code here on GitHub!

Includes

Solution

solution()
Returns:

The solution to problem 7

Return type:

number

 1-- Project Euler Problem 7
 2--
 3-- Problem:
 4--
 5-- By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that
 6-- the 6th prime is 13.
 7--
 8-- What is the 10 001st prime number?
 9
10local primes = loadlib("primes").primes
11
12return {
13    solution = function()
14        local num
15        local idx = 0
16        local pgen = primes()
17
18        repeat
19            idx = idx + 1
20            num = pgen.next()
21        until idx > 10000
22
23        return num
24    end
25}

Tags: factorization, prime-number, lua-iterator