On 6/16/08, June Kim <[EMAIL PROTECTED]> wrote:
> Given the shape of a mine field, generate the field with the
> probability of 1/8 for mine's presence for each cell. Then display the
> graphical representation and the hint for each cell. Hint for one cell
> is the number of mines in max 8 neighbouring cells, except when there
> is a mine in the cell, in which case the hint is '*' instead.
After writing my own implementation of this and looking at
yours, I seem to have come up with essentially the same
approach that you used:
board=: 0 = [EMAIL PROTECTED]&8
hint=: {"0 1 '*',"0~(1 1,:3 3) ({.@":@(+/)@,;._3) 0,0,.0,~0,.~]
(;hint) board 4 5
+---------+-----+
|0 0 0 0 0|01110|
|0 0 1 0 0|12*10|
|1 0 0 0 0|*3221|
|0 1 0 0 1|2*11*|
+---------+-----+
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm