aboutsummaryrefslogtreecommitdiff
path: root/challenge-147/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-147/abigail/lua/ch-2.lua')
-rw-r--r--challenge-147/abigail/lua/ch-2.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-147/abigail/lua/ch-2.lua b/challenge-147/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..1d93585f24
--- /dev/null
+++ b/challenge-147/abigail/lua/ch-2.lua
@@ -0,0 +1,29 @@
+#!/opt/local/bin/lua
+
+--
+-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-147
+--
+
+--
+-- Run as: lua ch-2.lua
+--
+
+pentagon = {}
+p = 0
+n = 0
+
+while true do
+ p = p + n + n + n + 1
+ n = n + 1
+ pentagon [p] = 1
+ for seen in pairs (pentagon) do
+ if seen + seen <= p and pentagon [p - seen] ~= nil
+ and pentagon [p - seen - seen] ~= nil then
+ print (seen .. " " .. (p - seen))
+ goto end_of_while
+ end
+ end
+end
+
+::end_of_while::
+