# [Community Puzzle] Minesweeper (old medium puzzle)

https://www.codingame.com/training/medium/minesweeper

Hello,

Je suis pas spécialement un expert en démineur mais j’ai l’impression pour ne pas dire certitude que l’output de l’example est faux.

Input
6 6
4
.1???1
.11211
11…
?2…
?2…
11…

On a dans cet exemple simple 5 possibilités de mine aux coordonnées suivantes :
0-2; 0-3; 0-4; 3-0; 4-0

Si on suit les règles et l’input, l’output réponse devrait être :
0-2; 0-4; 3-0; 4-0
et non pas
0-3; 0-4; 2-0; 4-0

Des bisous,

Geff

You swapped the coordinates: column should come first.

1 Like

oh my bad, i guess i need some sleep

Geff

hello, once again, i get 100% ide but only 60 % when submitting…
I don’t know if i m doing wrong.
here is a debug trace of how i found and demine, but i can’t really see my mistake.

``````??1..
??1..
11222
..1??
..1??

?.0..
.m0..
00122
..1??
..1??

?.0..
.m0..
00011
..0m?
..0.?

?.0..
.m0..
00000
..0mm
..0.?

?.0..
.m0..
00000
..0mm
..0.?

3 mines to look for, so the algorithm stop here
``````

thx

I am not able to understand the test case “Hidden Mines”. I discovered the possible mine locations like the following:
(* - mines)

``````.....
..122
..2**
..3*?
..2*?
``````

But the output considers the location of two “?” also. Could you please explain why is that? Is it because no of hidden mines (nb) in input is 6?

Note: “?” at (3,4) can be replaced with number 4 and “?” at (4,4) with number 2.

Which mines to select if input is 14 for no of hidden mines (nb) for the following example?

``````*1....1*.
.2....12*
*1.....11
11.......
12221..11
*.**2112*
???*21*..
???.32.??
???*2*.??
``````

@codybumba
in fact you can’t resolved the last two interrogations…
but you know that they are 6 mines in total (from input) in this configuration,
and you discover 4 of them,
so the last two ‘?’ must be the last 2 mines to reach 6

it is one part of this puzzle.

I’m a bit disapointed, I thought solving this puzzle would compel me to find mines more efficiently to improve my solver for the interactive version (Coding Games and Programming Challenges to Code Better) but actually the basic check I use in the interactive version still works here and gets me 100%.
I challenged most user solutions with this very easy custom validator:

``````3 3
2
???
121
...
``````

and almost none of them finds the mines (0 0 and 2 0), meaning most of us went lazy for this puzzle

1 Like

@pardouin this kind of pattern recognition will be useful in the next minesweeper… https://www.codingame.com/training/medium/minesweeper-1

Well, I don’t have much time to improve solutions of already completed puzzles (I’d like to complete all medium puzzles and it’s pretty long, 43% so far and I’m happy when I can grind 5% per week), but I’ll definitively give it a try later.

I see how this can be done, testing all combinations of mines in the neighboorhood of a digit and when only one of them doesn’t contradict the other digits, it’s the good one.
It seems pretty straightforward to implement but my code is already spaghetti-ish and if I want to add this properly I’d have to do a bit of cleaning before

I assume this is why I am failing validator 4, as I believe it is timing out because it is never able to resolve this pattern. Test case 4 doesn’t have that pattern. It’s a little bit evil that it got snuck into the validator, if so.

i agree with you

I think the last test (Final Test) should pass with the solution below as well (I got 100% after submission without passing the latter test):

0 1 (instead of 0, 0)
0 2
1 5 (instead of 0, 0)
2 5
3 5
3 6
3 8
5 8
6 6
7 0
8 1
8 5

If I go through the grid visually step by step, the solution above makes perfect sense (unless I was wrong in my reasoning of course!)

There’s a 1 in cell (1, 2), but your solution suggests (0, 1) and (0, 2), so there’s 1 mine too many.

You were right, I’ve re-written my loop in a different way. Now all tests pass but the last validation test doesn’t after submission. Nevermind, 80% looks good enough, I give up , it took me a while to pass that last test

I don’t understand why this code doesn’t work for the fourst validator test but work for the IDE…
Do you have any clue?

[mod edit: don’t post full code on the forum]

You may send me your code by private message and I’ll take a look. Remember to format your code properly by using the </> button on the formatting toolbar.

1 Like

The following custom case may help those who fail Validator 4:

Input

``````6 9
12
....2????
....2????
..1122332
..1?1....
113?3????
1?????...
``````

Output

``````1 5
3 3
3 5
4 5
5 0
5 1
6 0
6 1
7 0
7 1
8 0
8 1
``````