I think that LuaTeX is ideal for such tasks. Below is a ConTeXt solution which should be easy to translate to LaTeX (it just sets the elements in a table).
\startsetups table:square
\setupTABLE[width=2em, height=2em, align={middle,lohi}]
\stopsetups
\starttext
\startluacode
context.bTABLE({"setups=table:square"})
local flag; flag = false;
for i=0,9 do
context.bTR()
for j=1,10 do
context.bTD()
if flag then
context.math(i*10 + j)
else
flag = true
end
context.eTD()
end
context.eTR()
end
context.eTABLE()
\stopluacode
\stoptext

The biggest advantage is that the code is easy to read and understand. Using a "normal" programming language also makes it easy to add more bells and whistles. For example, here is a version that highlights the primes. I use a naive algorithm to check for a prime, and simply set the background color if the number is a prime.
\startsetups table:square
\setupTABLE[width=2em, height=2em, align={middle,lohi}, background=color]
\stopsetups
\startluacode
-- This is a naive implementation just for illustration
thirddata = thirddata or {}
function thirddata.isPrime(num)
if (num == 2) then
return true
end
if (num <= 1) or (num % 2 == 0) then
return false
end
for i = 3, num^(1/2), 2 do
if num % i == 0 then
return false
end
end
return true
end
\stopluacode
\starttext
\startTEXpage[offset=3mm]
\startluacode
context.bTABLE({"setups=table:square"})
local flag; flag = false;
local function setBackground(boolean)
if boolean then
return "backgroundcolor=lightred"
else
return ""
end
end
for i=0,9 do
context.bTR()
for j=1,10 do
context.bTD({setBackground(thirddata.isPrime(i*10 + j))})
if flag then
context.math(i*10 + j)
else
flag = true
end
context.eTD()
end
context.eTR()
end
context.eTABLE()
\stopluacode
\stopTEXpage
\stoptext

Again, the main advantage of LuaTeX is the readability of the code.
DrawGridWithNumbers– Peter Grill Oct 11 '12 at 09:57