[ create a new paste ] login | about

Link: http://codepad.org/ZsNi8Ej5    [ raw code | output | fork ]

nepta - Lua, pasted on Apr 7:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function search(m, x)
   for i,v1 in ipairs(m) do
      for j,v2 in ipairs(v1) do
         if v2 == x then return i,j end
      end
   end
end

m = {
   {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},
}

local i,j = search(m,17)
print(string.format("m[%d][%d] = %d",i,j,m[i][j]))


Output:
1
m[4][2] = 17


Create a new paste based on this one


Comments: