aboutsummaryrefslogtreecommitdiff
path: root/challenge-283/roger-bell-west/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-283/roger-bell-west/lua/ch-2.lua')
-rwxr-xr-xchallenge-283/roger-bell-west/lua/ch-2.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-283/roger-bell-west/lua/ch-2.lua b/challenge-283/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..ef6f8fda89
--- /dev/null
+++ b/challenge-283/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,36 @@
+#! /usr/bin/lua
+
+function digitcountvalue(a)
+ local c = {}
+ for ix = 1, #a do
+ c[ix - 1] = 0
+ end
+ for _, n in ipairs(a) do
+ if c[n] == nil then
+ c[n] = 1
+ else
+ c[n] = c[n] + 1
+ end
+ end
+ for ix = 1, #a do
+ if a[ix] ~= c[ix - 1] then
+ return false
+ end
+ end
+ return true
+end
+
+if digitcountvalue({1, 2, 1, 0}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if not digitcountvalue({0, 3, 0}) then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+