aboutsummaryrefslogtreecommitdiff
path: root/challenge-121/abigail/lua/ch-1.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-121/abigail/lua/ch-1.lua')
-rw-r--r--challenge-121/abigail/lua/ch-1.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-121/abigail/lua/ch-1.lua b/challenge-121/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..52b7529007
--- /dev/null
+++ b/challenge-121/abigail/lua/ch-1.lua
@@ -0,0 +1,23 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+for line in io . lines () do
+ _, _, m, n = line : find ("(%d+)%s+(%d+)")
+ x = 1
+ for i = 1, n - 1 do
+ x = x * 2
+ end
+ if math . floor (m / x) % 2 == 1 then
+ m = m - x
+ else
+ m = m + x
+ end
+ print (m)
+end