aboutsummaryrefslogtreecommitdiff
path: root/challenge-251/roger-bell-west/lua/ch-1.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-251/roger-bell-west/lua/ch-1.lua')
-rwxr-xr-xchallenge-251/roger-bell-west/lua/ch-1.lua49
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-251/roger-bell-west/lua/ch-1.lua b/challenge-251/roger-bell-west/lua/ch-1.lua
new file mode 100755
index 0000000000..e893bf6fbd
--- /dev/null
+++ b/challenge-251/roger-bell-west/lua/ch-1.lua
@@ -0,0 +1,49 @@
+#! /usr/bin/lua
+
+function concat(a0, b0)
+ if b0 == 0 then
+ return 10 * a0
+ end
+ local a = a0
+ local b = b0
+ while b > 0 do
+ a = a * 10
+ b = math.floor(b / 10)
+ end
+ return a + b0
+end
+
+function concatenationvalue(a)
+ local t = 0
+ for i = 1, math.floor((#a + 1) / 2) do
+ local j = #a + 1 - i
+ if j == i then
+ t = t + a[i]
+ else
+ t = t + concat(a[i], a[j])
+ end
+ end
+ return t
+end
+
+if concatenationvalue({6, 12, 25, 1}) == 1286 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if concatenationvalue({10, 7, 31, 5, 2, 2}) == 489 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if concatenationvalue({1, 2, 10}) == 112 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+