Lua Implementation of Problem 3

View source code here on GitHub!

Includes

Solution

solution()
Returns:

The solution to problem 3

Return type:

number

 1-- Project Euler Problem 3
 2--
 3-- Problem:
 4--
 5-- The prime factors of 13195 are 5, 7, 13 and 29.
 6--
 7-- What is the largest prime factor of the number 600851475143 ?
 8
 9local prime_factors = loadlib("primes").prime_factors
10
11return {
12    solution = function()
13        local fgen = prime_factors(600851475143)
14        local f, answer
15
16        repeat
17            answer = f
18            f = fgen.next()
19        until not f
20
21        return answer
22    end
23}

Tags: factorization, prime-number, lua-iterator