24. April 2008 21:03
/
jfollas
/
Blog
/
Comments (0)
It seems that a lot of my friends are doing Project Euler (according to my High School math teacher, this is pronounced "Oiler"). For example, Bill Wagner has been posting C# solutions, Darrell Hawley has ventured into the Python realm, and Dustin Campbell has been working on F# versions.
I love numbers, and spent a good portion of one summer playing with primes and number fields just for fun (since then, I've discovered WoW, and that takes up all of my time that would otherwise be spent exercising my brain). Project Euler is actually right up my alley, and while in Seattle, I joked with Dustin that I should post solutions using LUA, and use World of Warcraft as my testbed...
Problem 1 is finished. :-D
My no-frills WoW add-on is a simple ACE2 mod that includes AceConsole (for printing to the chat window in the lower left of the screenshot). I won't bore you with the framework code, but will list my solutions as individual functions on my wiki (where it can grow without polluting my blog's RSS feed).
As a taste, here's the Problem 1 solution written in LUA. OnEnable() is my add-on's entry point, and it simply calls into the function Problem001(limit).
function ProjectEuler:OnEnable()
ProjectEuler:Problem001(1000)
end
function ProjectEuler:Problem001(upperLimit)
self:Print("Sum of all numbers less than " .. upperLimit .. " that are divisible by 3 or 5")
local f = function(factor)
local n = math.ceil(upperLimit / factor)
return n * (n-1) * factor / 2
end
local result = f(3) + f(5) - f(15)
self:Print(result)
end
b305eb92-a3f2-42ae-9c34-b2cca9bbb922|1|1.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04