aboutsummaryrefslogtreecommitdiff
path: root/challenge-137/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-137/abigail/lua/ch-2.lua')
-rw-r--r--challenge-137/abigail/lua/ch-2.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-137/abigail/lua/ch-2.lua b/challenge-137/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..1cfb4f84e9
--- /dev/null
+++ b/challenge-137/abigail/lua/ch-2.lua
@@ -0,0 +1,34 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+function reverse (num)
+ local rev = 0
+ while num > 0 do
+ rev = rev * 10
+ rev = rev + (num % 10)
+ num = math . floor (num / 10)
+ end
+ return (rev)
+end
+
+
+function ly (n)
+ if n >= 10000000
+ then return (1)
+ elseif n == reverse (n)
+ then return (0)
+ else return (ly (n + reverse (n)))
+ end
+end
+
+
+for number in io . lines () do
+ print (ly (tonumber (number)))
+end