aboutsummaryrefslogtreecommitdiff
path: root/challenge-283/roger-bell-west/lua/ch-2.lua
blob: ef6f8fda89ca31ec4cd32d6f94c67bef471bc433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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("")