Updated problems to be more in line with conventions

This commit is contained in:
2020-06-19 19:58:36 -04:00
parent 1bfd097fa3
commit 7d107c1071
31 changed files with 174 additions and 182 deletions

View File

@@ -1,11 +1,11 @@
--ProjectEuler/lua/Problem21.lua
--Matthew Ellison
-- Created: 03-19-19
--Modified: 03-28-19
--Modified: 06-19-20
--Evaluate the sum of all the amicable numbers under 10000
--All of my requires, unless otherwise listed, can be found at https://bitbucket.org/Mattrixwv/luaClasses
--[[
Copyright (C) 2019 Matthew Ellison
Copyright (C) 2020 Matthew Ellison
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -29,26 +29,26 @@ LIMIT = 10000; --The top number that will be evaluated
--Setup the timer
timer = Stopwatch:create();
local timer = Stopwatch:create();
--Setup the variables
divisorSum = {}; --Holds the sum of the factors of the subscript number
local divisorSum = {}; --Holds the sum of the factors of the subscript number
--Start the timer
timer:start();
--Generate the factors of all the numbers < 10000, get their sum, and add it to the list
for cnt = 1, LIMIT do
divisors = getDivisors(cnt); --Get all the divisors of a number
local divisors = getDivisors(cnt); --Get all the divisors of a number
if(#divisors > 1) then
table.remove(divisors); --Remove the last entry because it will be the number itself
end
divisorSum[#divisorSum + 1] = getSum(divisors); --Add the sum of the divisors to the vector
end
--Check every sum of divisors in the list for a matching sum
amicable = {};
local amicable = {};
for cnt = 1, #divisorSum do
sum = divisorSum[cnt];
local sum = divisorSum[cnt];
--If the sum is greater than the number of divisors then it is impossible to be amicable. Skip the number and continue
if(sum >= #divisorSum) then
--We know that divisorSum[cnt] == sum, do if divisorSum[sum] == cnt we have found an amicable number