aboutsummaryrefslogtreecommitdiff
path: root/challenge-182/roger-bell-west/lua/ch-1.lua
blob: 5e1e0c4887e6c0f30f529b2e525ed927a0650117 (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
#! /usr/bin/lua

function maxindex(n)
   local mxv = 0
   local mxi = 0
   for i, v in ipairs(n) do
      if i == 1 or v > mxv then
         mxv = v
         mxi = i
      end
   end
   return mxi-1
end

if maxindex({5, 2, 9, 1, 7, 6}) == 2 then
   io.write("Pass")
else
   io.write("FAIL")
end
io.write(" ")

if maxindex({4, 2, 3, 1, 5, 0}) == 4 then
   io.write("Pass")
else
   io.write("FAIL")
end
io.write(" ")

if maxindex({4, 2, 3, 1, 4, 0}) == 0 then
   io.write("Pass")
else
   io.write("FAIL")
end
print("")