mirror of
https://bitbucket.org/Mattrixwv/projecteulerlua.git
synced 2025-12-06 17:43:57 -05:00
52 lines
1.5 KiB
Lua
52 lines
1.5 KiB
Lua
--ProjectEuler/lua/Problem1.lua
|
|
--Matthew Ellison
|
|
-- Created: 02-01-19
|
|
--Modified: 03-28-19
|
|
--What is the sum of all the multiples of 3 or 5 that are less than 1000
|
|
--All of my requires, unless otherwise listed, can be found at https://bitbucket.org/Mattrixwv/luaClasses
|
|
--[[
|
|
Copyright (C) 2019 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
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
]]
|
|
|
|
|
|
require "Stopwatch"
|
|
|
|
|
|
timer = Stopwatch:create();
|
|
timer:start();
|
|
|
|
TOP_NUMBER = 999; --This is the largest number that you are going to check
|
|
sumOfMultiples = 0;
|
|
for num = 1, TOP_NUMBER do
|
|
if((num % 3) == 0) then
|
|
sumOfMultiples = sumOfMultiples + num;
|
|
elseif((num % 5) == 0) then
|
|
sumOfMultiples = sumOfMultiples + num;
|
|
end
|
|
end
|
|
|
|
timer:stop()
|
|
|
|
--Print the results
|
|
print("The sum of all numbers < 1000 is " .. sumOfMultiples);
|
|
print("It took " .. timer:getMicroseconds() .. " microseconds to run this algorithm");
|
|
|
|
|
|
--[[Results:
|
|
The sum of all numbers < 1000 is 233168
|
|
It took 148 microseconds to run this algorithm
|
|
]]
|