summaryrefslogtreecommitdiffstats
path: root/6.lua
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-13 23:32:40 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-13 23:32:40 -0500
commit7e7b56db42ceb8d2b8973eae678fa4b58d5d3659 (patch)
tree7a5cb816809d632e30227c1e39485ed63b500e80 /6.lua
downloadprojecteuler-7e7b56db42ceb8d2b8973eae678fa4b58d5d3659.tar.gz
projecteuler-7e7b56db42ceb8d2b8973eae678fa4b58d5d3659.zip
add old solutions
Diffstat (limited to '6.lua')
-rw-r--r--6.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/6.lua b/6.lua
new file mode 100644
index 0000000..3c39a4b
--- /dev/null
+++ b/6.lua
@@ -0,0 +1,13 @@
+local function sum_of_squares(n)
+ local total = 0
+ for i = 1, n do
+ total = total + i^2
+ end
+ return total
+end
+
+local function square_of_sum(n)
+ return n^2*(n+1)^2/4
+end
+
+print(square_of_sum(100) - sum_of_squares(100))