Skip to content

Commit

Permalink
fix p10, stylistic change in p3
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 18, 2024
1 parent 07e70fb commit 110c102
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lua/src/lib/primes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ local function primes(stop)
local function next()
if stop and prime >= stop then
sieve = {}
error("Tried to exceed given limit")
return nil, "Tried to exceed given limit"
end

prime = next_prime(candidate)
candidate = prime + 1

if stop and prime >= stop then
sieve = {}
return nil, "Tried to exceed given limit"
end

return prime
end

Expand Down
6 changes: 3 additions & 3 deletions lua/src/p0003.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ local prime_factors = loadlib("primes").prime_factors
return {
solution = function()
local fgen = prime_factors(600851475143)
local f = fgen.next()
local f
local answer = 0

while f do
repeat
answer = f
f = fgen.next()
end
until not f

return answer
end
Expand Down
2 changes: 1 addition & 1 deletion lua/src/p0010.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ return {
repeat
answer = answer + tmp
tmp = pg.next()
until tmp == nil
until not tmp

return answer;
end
Expand Down

0 comments on commit 110c102

Please sign in to comment.