Hacker News new | ask | show | jobs
by parennoob 4311 days ago
"There are basically two main types of candidates: the candidate who approaches the problem and says "I need to loop over every cell in sequence and assign a mine or not based on a random probability! Wait, what do you mean, I need to get a specific number of mines on the board? I'm not sure I can make that happen" ... and the candidate who's worth hiring."

Since this interviewer seems to have made up their mind already with pre-conceptions of which candidate is worth hiring, what is the "correct" answer to this question? "Pick random co-ordinates, check, and retry?". I'd like to know, so I can give that as my first answer if I come up before such a person in the interview.

This right here is why everyone tries to game the system and come out with the "worth hiring" answer as if they had thought it out themselves. We are not even given an opportunity to ask questions, maybe come up with an answer, say "That's not optimal", and work towards a good answer -- which is the flow you would use for working at your day-to-day job. And, for the record, I started playing Minesweeper last year, and hadn't even touched it back in the day.

2 comments

Any answer that gets the job done works. Looping through the mines in one pass with appropriate adjustment of probability (never seen it). Pick random spot and retry. Take all coordinates, shuffle, take N. Something I've never heard of? Sure, if you apply it and it works.

The preconception is that someone who isn't capable of coming up with a way to distributing X values into a data structure representing a M*N playing field isn't worth hiring. It's a stupidly simple task, light on the algorithms (much like the day-to-day programming tasks) and heavier on the "come up with something coherent and quasi-organized to accomplish a very simple goal" in a program.

As for the rules of Minesweeper, if you're rusty, I have a printout. :b

>Since this interviewer seems to have made up their mind already with pre-conceptions of which candidate is worth hiring, what is the "correct" answer to this question? "Pick random co-ordinates, check, and retry?"

The most efficient way (which is arguably unnecessary for Minesweeper) is to treat a 10x10 play field as a 1 dimensional array of size 100, stick your X number of mines in the first X cells in the array, then use something like the Fisher-Yates shuffle* on the array.

* Y = random number 1-100. Swap contents of cell Y and cell 100. Y = random number 1-99, swap contents of cell Y and cell 99. Repeat for entire array.