Is it possible to construct a program that only gives just sufficient hints to enable the position of the mines in the minefield to be logically deducted? In other words to turn this exercise into a puzzle?
The unnecessary hints would be shown as spaces. Richard Donovan > Date: Tue, 17 Jun 2008 03:01:01 +0900 > From: [EMAIL PROTECTED] > To: [email protected] > Subject: [Jprogramming] Mine Sweeper > > Problem: > 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. > > Example: > ....* > ..... > ..*.. > .*... > > 0001* > 01121 > 12*10 > 1*210 > > > > ------------------ > Following is my solution: > > board=:0 = [: ? 8 $~ ] > graphic=: '.*' {~ ] > guard=: 0 ,.~ 0 ,. 0 ,~ 0 , ] > hintsc=: (1 1,:3 3)+/@,;._3 guard > hintscs=:[: ,"2 [: ":&> hintsc > hint=:[: ,"2 hintsc ":@[`('*'"_)@.] every ] > > Usage example: > > (graphic,:hint) b=.board 4 5 > > Could you suggest any ways to improve the code? I am particulary > dissatisfied with the use of agenda for substituting '*"s at the > mine's places. > > Of course, different approaches are welcome. I would appreciate it for > the learning opportunity. > > June Kim > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm _________________________________________________________________ All new Live Search at Live.com http://clk.atdmt.com/UKM/go/msnnkmgl0010000006ukm/direct/01/---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
