Here you go:
function setup()
bigTable =
{
{0, 0, 0, 0, 1, 1, 0, 0},
{0, 0, 0, 1, 0, 0, 1, 0},
{0, 0, 0, 1, 0, 0, 1, 0},
{0, 0, 0, 0, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
}
littleTable =
{
{0, 1, 1, 0},
{1, 0, 0, 1},
{1, 0, 0, 1},
{0, 1, 1, 0}
}
if tableIn(littleTable,bigTable,1) then
print("Success")
else
print("Failure")
end
end
function draw()
end
function tableIn(lt,bt,me)
me = me or 1 -- number of allowed errors
-- big table dimensions
local br = #bt
local bc = #bt[1]
-- little table dimensions
local lr = #lt
local lc = #lt[1]
-- offset range
local mr = br - lr
local mc = bc - lc
-- loop over the offsets looking for a match
for i=0,mr do
for j=0,mc do
-- if we get a match, return true
-- otherwise continue with the search
if tableIn_aux(lt,bt,i,j,lr,lc,me) then
return true
end
end
end
-- no match found, return false
return false
end
function tableIn_aux(lt,bt,i,j,lr,lc,me)
local err = 0
for k=1,lr do
for l=1,lc do
if lt[k][l] ~= bt[k+i][l+j] then
err = err + 1
end
if err >= me then
return false
end
end
end
return true
end