-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e167c33
commit 7fdef1d
Showing
6 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Lua Implementation of Problem 5 | ||
=============================== | ||
|
||
View source code :source:`lua/src/p0005.lua` | ||
|
||
Includes | ||
-------- | ||
|
||
- `primes.lua <./lib/primes.html>`__ | ||
|
||
Solution | ||
-------- | ||
|
||
.. lua:function:: solution() | ||
:return: The solution to problem 5 | ||
:rtype: number | ||
|
||
.. literalinclude:: ../../../lua/src/p0005.lua | ||
:language: Lua | ||
:linenos: | ||
|
||
.. tags:: factorization, prime-number, lua-iterator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
-- Project Euler Problem 5 | ||
-- | ||
-- Problem: | ||
-- | ||
|
||
local prime_factors = loadlib("primes").prime_factors | ||
|
||
return { | ||
solution = function() | ||
local answer = 1 | ||
local factorTracker = {} | ||
local localFactorTracker = {} | ||
for i = 1,20 do | ||
factorTracker[i] = 0 | ||
localFactorTracker[i] = 0 | ||
end | ||
|
||
for i = 2,20 do | ||
local pf = prime_factors(i) | ||
local p = pf.next() | ||
repeat | ||
localFactorTracker[p] = localFactorTracker[p] + 1 | ||
p = pf.next() | ||
until not p | ||
|
||
for j = 2,19 do | ||
if factorTracker[j] < localFactorTracker[j] then | ||
factorTracker[j] = localFactorTracker[j] | ||
end | ||
localFactorTracker[j] = 0 | ||
end | ||
end | ||
for i = 2,19 do | ||
for j = 1,factorTracker[i] do | ||
answer = answer * i | ||
end | ||
end | ||
|
||
return answer | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters