mirror of
https://bitbucket.org/Mattrixwv/projecteulerlua.git
synced 2025-12-06 17:43:57 -05:00
Updated problems to be more in line with conventions
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
--ProjectEuler/lua/Problem20.lua
|
||||
--Matthew Ellison
|
||||
-- Created: 03-14-19
|
||||
--Modified: 03-28-19
|
||||
--Modified: 06-19-20
|
||||
--What is the sum of the digits of 100!
|
||||
--All of my requires, unless otherwise listed, can be found at https://bitbucket.org/Mattrixwv/luaClasses
|
||||
--I used the bigint library from https://github.com/empyreuma/bigint.lua
|
||||
--[[
|
||||
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
|
||||
@@ -30,7 +30,7 @@ TOP_NUM = 100;
|
||||
|
||||
|
||||
--Start the timer
|
||||
timer = Stopwatch:create();
|
||||
local timer = Stopwatch:create();
|
||||
timer:start();
|
||||
|
||||
local num = bigint.new(1); --The number to be generated
|
||||
@@ -41,7 +41,7 @@ for cnt = 1, TOP_NUM do
|
||||
end
|
||||
|
||||
--Get a string of the number because it is easier to pull appart the individual characters to get the sum
|
||||
numString = bigint.unserialize(num, 's');
|
||||
local numString = bigint.unserialize(num, 's');
|
||||
--Run through every character in the string, convert it back to an integer and add it to the running sum
|
||||
for cnt = 1, string.len(numString) do
|
||||
sum = sum + tonumber(string.sub(numString, cnt, cnt));
|
||||
|
||||
Reference in New Issue
Block a user