MATLAB, 94 93 bytes
rng(input(''));x(9,9)=~1;x(randperm(81,10))=1;y=[conv2(+x,ones(3),'s')+48 ''];y(x)=42;disp(y)
Example run (the first line after the code is the input typed by the user):
>> rng(input(''));x(9,9)=~1;x(randperm(81,10))=1;y=[conv2(+x,ones(3),'s')+48 ''];y(x)=42;disp(y)
99
*10001*2*
220001232
*201111*1
*312*1111
12*211000
011211000
0001*1000
000112110
000001*10
Explanation
rng(input(''));
takes an integer and uses it as seed. (This works in modern MATLAB versions. Old versions may need a different syntax.)
x(9,9)=~1;
assigns logical 0
, or false
(obtained by logically negating 1
) to the entry (9,9)
of a matrix x
. The rest of the entries are automatically initiallized to logical 0
too.
x(randperm(81,10))=1;
assigns 1
(autoomatically cast to logical 1
, or true
) to 10
of the
81
entries of x
, chosen randomly without replacement. These entries are the ones that contain bombs.
conv2(+x,ones(3),'s')
is an abbreviation of conv2(+x,ones(3),'same')
. It convolves the matrix x
(which needs to be cast to double
, using +
) with a 3×3 neighbourhood containing 1
. This counts how many bombs are adjacent to each entry. For entries that contain a bomb it includes that bomb, but the value there will be overwritten later.
y=[...+48 ''];
adds 48 to the value, to convert from number to ASCII code. Concatenating with the empty matrix casts these ASCII codes to chars.
y(x)=42;
assigns 42 (ASCII code for '*'
) to the positions of the bombs. These positions are given by x
, which is here used as a logical index.
disp(y)
displays the result.