r/dailyprogrammer • • Oct 27 '12
[10/27/2012] Challenge #108 [Intermediate] (Minesweeper Generation)
For the intermediate challenge, you will have to generate a Minesweeper game. Minesweeper boards have three attributes, length, width, and number of mines. Given the input below, output a correct gameboard.
Minesweeper games have two types of pieces, mines, and non-mines. The non-mines have a number, which is the number of mines adjacent to it.
For example: Here's an image of a Minesweeper game.
Your input is...
- Height: 15
- Width: 15
- Mines: 20
Good luck and have fun!
33
Upvotes
36
u/[deleted] Oct 27 '12
J:
As a cute one-liner:
7
u/skeeto -9 8 Oct 27 '12 edited Oct 28 '12
In Common Lisp,
Output:
3
u/andkerosine Oct 27 '12
Ruby:
Sample output
5
u/lordtnt Oct 27 '12
Python
2
u/prondose 0 0 Oct 28 '12 edited Oct 29 '12
Perl6:
2
u/bradengroom Oct 28 '12
Perl:
2
u/drabred Oct 30 '12 edited Oct 30 '12
Hi 1st post in /r/dailyprogrammers, C# cheers :) Outcome: http://i.imgur.com/TFLyb.jpg/
2
u/ahlk 0 0 Nov 24 '12
Perl
output for height: 20 width: 20 mines: 20
3
u/[deleted] Oct 27 '12
Common Lisp
3
u/[deleted] Oct 27 '12
Java (I'm new to programming so it's a little sloppy):
3
u/wintron 0 0 Oct 27 '12
Guess I have to find a new interview question
2
u/flatterflatflatland 0 0 Oct 27 '12 edited Oct 28 '12
Java
After reading other answers... much more readable then before.
And sample output:
2
u/bigmill Oct 27 '12
Loving this subreddit!
C# Represent!
1
u/MrSquig 0 1 Oct 27 '12 edited Oct 27 '12
Python:
Sample output:
1
u/Okashu Oct 28 '12
It ALMOST works, but has problems with border tiles due to way it works. Any way to make it work without rewriting whole code?
1
u/Raian1614 Oct 29 '12 edited Dec 02 '12
Where you see int() used is becuase in the original program I error checked for when the user enters strings/decimals and so the they were strings instead of integers...
...Sample Output...
1
u/beezeee Oct 29 '12
Javascript: (function() {
1
u/seanchaotic Oct 30 '12
In PHP:
Used like this:
With output like:
1
u/CMens Oct 30 '12
C++:
1
u/koloron Oct 31 '12
Python3:
1
u/redried Nov 01 '12 edited Nov 01 '12
Another beginner, in Javascript/JQuery. Playable (roughly) at http://jsfiddle.net/5RZ9z/1/
1
u/larg3-p3nis Nov 02 '12
Messy Java, just happy I could complete my first intermediate challenge.
Output:
1
u/shivasprogeny Nov 03 '12
Java. I challenged myself to do this without 2D arrays for fun.
}
1
u/[deleted] Nov 17 '12
I'm almost a month late on this boat, but what the hell.
In hacky python
1
u/fabzter Nov 20 '12
Late to the party, comments accepted :D
1
u/ben174 Nov 27 '12
Python:
1
u/[deleted] Dec 01 '12 edited Dec 01 '12
LUA:
Sample Output:
1
u/JonasW87 0 0 Dec 07 '12
Very late to the party but here we go!
Saw that my solution was very similar to seanchaotic's without even looking at it :)
Output:
1
u/marekkpie Jan 09 '13
Lua. I was going to do it more functionally, but I wanted to work on my Lua classes.
1
u/deds_the_scrub Mar 11 '13
Here's mine in python:
1
u/chezmonkey Oct 28 '12
I have been working on a Minesweeper app for Android and this is relevant to my interests.
https://github.com/bngo92/Minesweeper-Teacher if you want to check it out.
Java:
1
u/prophile Oct 27 '12
Some Ruby, my first time properly playing with it:
1
u/shandelman Oct 27 '12 edited Oct 27 '12
A very non-Pythonic attempt in Python:
A sample board can be gotten by using:
1
u/strider978 Oct 28 '12
Just learning C++ (and programming in general). I'm sure there's lots of way's to make this more concise (specifically by writing a few more functions) but I had fun and it works well.
1
u/iMalevolence Oct 28 '12
Java
Cleared out a lot of the unnecessary code. Creating a MineSweeper object and calling ms.printCount() should do it.
1
u/Nowin Oct 28 '12 edited Oct 28 '12
First post. Critics welcome. I wrote this in 10 minutes, so realize that I didn't do any testing...
Java:
example output:
0
u/gammadistribution 0 0 Nov 08 '12
Python 2.7:
Sample Output:
0
u/[deleted] Oct 27 '12
[deleted] — view deleted comment