A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Linear Search in Lua page! Here, you'll find the source code for this program as well as a description of how the program works.
local args = {...}
local nums_str = args[1]
local key = tonumber(args[2])
local numbers = {}
local found = false
if #args ~= 2 then
print('Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")')
return
end
if not key then
print('Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")')
return
end
if #nums_str < 1 then
print('Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")')
return
end
for num in string.gmatch(nums_str, '([^,]+)') do
table.insert(numbers, tonumber(num))
end
for i = 1, #numbers do
if numbers[i] == key then
found = true
break
end
end
print(found and "true" or "false")
Linear Search in Lua was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.