aboutsummaryrefslogtreecommitdiff
path: root/challenge-091/paulo-custodio/lua/ch-2.lua
blob: 93fdabe41b29deb3fa692e4be210c68d761c1a50 (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
#!/usr/bin/env lua

--[[
Challenge 091

TASK #2: Jump Game

You are given an array of positive numbers @N, where value at each index
determines how far you are allowed to jump further. Write a script to decide
if you can jump to the last index. Print 1 if you are able to reach the last
index otherwise 0.
--]]

N = {}

for i=1,#arg do
    table.insert(N, tonumber(arg[i]))
end

p = 1
while (p < #N and N[p] ~= 0) do
    p = p + N[p]
end

if (p == #N) then
    io.write(1, "\n")
else
    io.write(0, "\n")
end