From 5e61259702034cbec63ade467ac7d3575a2f686c Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Fri, 5 Feb 2021 00:13:38 +0000 Subject: Add missing local in variables --- challenge-003/paulo-custodio/lua/ch-1.lua | 2 +- challenge-003/paulo-custodio/lua/ch-2.lua | 4 ++-- challenge-097/paulo-custodio/lua/ch-1.lua | 2 +- challenge-098/paulo-custodio/lua/ch-1.lua | 6 +++--- challenge-098/paulo-custodio/lua/ch-2.lua | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/challenge-003/paulo-custodio/lua/ch-1.lua b/challenge-003/paulo-custodio/lua/ch-1.lua index 525469191a..5c40f03256 100644 --- a/challenge-003/paulo-custodio/lua/ch-1.lua +++ b/challenge-003/paulo-custodio/lua/ch-1.lua @@ -16,7 +16,7 @@ seq5 = {1} function next_hamming() -- get the smallest of the queue heads - n = math.min(seq2[1], seq3[1], seq5[1]) + local n = math.min(seq2[1], seq3[1], seq5[1]) -- shift used multiples if n == seq2[1] then table.remove(seq2, 1); end diff --git a/challenge-003/paulo-custodio/lua/ch-2.lua b/challenge-003/paulo-custodio/lua/ch-2.lua index d8c661014c..8853469774 100644 --- a/challenge-003/paulo-custodio/lua/ch-2.lua +++ b/challenge-003/paulo-custodio/lua/ch-2.lua @@ -10,7 +10,7 @@ information about Pascal Triangle, check this wikipedia page. --]] function draw_pascal(rows) - data = {1} + local data = {1} for row=1,rows do -- print current row for col=1,rows-row do io.write(" "); end @@ -18,7 +18,7 @@ function draw_pascal(rows) io.write("\n") -- compute next row - nxt = {1} + local nxt = {1} for col=1,row-1 do table.insert(nxt, data[col] + data[col+1]) end diff --git a/challenge-097/paulo-custodio/lua/ch-1.lua b/challenge-097/paulo-custodio/lua/ch-1.lua index 4bb62c085d..46c6b0f418 100644 --- a/challenge-097/paulo-custodio/lua/ch-1.lua +++ b/challenge-097/paulo-custodio/lua/ch-1.lua @@ -22,7 +22,7 @@ Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD --]] function caesar(n, text) - text = string.upper(text) + local text = string.upper(text) local cipher = "" for i=1, #text do diff --git a/challenge-098/paulo-custodio/lua/ch-1.lua b/challenge-098/paulo-custodio/lua/ch-1.lua index fa72bd2be5..90124c6509 100644 --- a/challenge-098/paulo-custodio/lua/ch-1.lua +++ b/challenge-098/paulo-custodio/lua/ch-1.lua @@ -21,15 +21,15 @@ Output: files = {} function readN(filename, n) - file = files[filename] + local file = files[filename] if file == nil then -- file not yet open file = io.open(filename, "r") files[filename] = file end - text = "" + local text = "" for i=1,n do - c = file:read(1) + local c = file:read(1) if c ~= nil then text = text..c end diff --git a/challenge-098/paulo-custodio/lua/ch-2.lua b/challenge-098/paulo-custodio/lua/ch-2.lua index c48e032d03..87053a6ea5 100644 --- a/challenge-098/paulo-custodio/lua/ch-2.lua +++ b/challenge-098/paulo-custodio/lua/ch-2.lua @@ -30,8 +30,8 @@ the index 4. -- search for index of element, insert in array if not found function search_insert(nums, n) - b = 1 - t = #nums + local b = 1 + local t = #nums if t < b then -- empty table.insert(nums, n) return 0 @@ -42,7 +42,7 @@ function search_insert(nums, n) table.insert(nums, n) return #nums-1 else - m = math.floor((t+b)/2) + local m = math.floor((t+b)/2) while b+1 < t do -- bisect loop if n == nums[m] then return m-1 -- cgit