aboutsummaryrefslogtreecommitdiff
path: root/challenge-091/paulo-custodio/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-091/paulo-custodio/lua/ch-2.lua')
-rw-r--r--challenge-091/paulo-custodio/lua/ch-2.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-091/paulo-custodio/lua/ch-2.lua b/challenge-091/paulo-custodio/lua/ch-2.lua
new file mode 100644
index 0000000000..c36f960435
--- /dev/null
+++ b/challenge-091/paulo-custodio/lua/ch-2.lua
@@ -0,0 +1,29 @@
+#!/usr/bin/env lua
+
+--[[
+THE WEEKLY 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