A couple of days ago somebody sent me an e-mail asking if I could write a program that generates binary puzzles. I didn’t know what binary puzzles were, but a search in google quickly led me to this site. Apparently, the “Binary” is a new kind of logic puzzle that involves only the numbers zero and one.
The goal is to fill in the grid with zeros and ones with the following restrictions:
- There are as many zeros as ones in every row and every column.
- No more than two of the same numbers can be next to or under each other.
- Rows or columns with the same content are not allowed.
Every puzzle has a unique solution, which in this case is:
The program I wrote uses the following algorithm to generate new puzzles. First it fills a grid with random zeros and ones in such a way that all restrictions apply. Then it removes numbers randomly while making sure that the puzzle maintains exactly one solution. When it has removed the right amount of numbers the puzzle is shown on screen. Click here to download the jar (source files are included) and read on for instructions on how to use the program.
The program is started from the command line.
First change directory to the location where you saved the .jar file. (NB: For some reason some browsers rename the binary.jar to binary.zip. You have to undo this name change manually.)
At the command prompt type:
java -jar Binary.jar <number of rows> <number of columns> <number of empty cells>
and the program generates a random puzzle according to the given specifications. Be aware however, that the puzzle may be agonizingly difficult to solve. As the puzzles are created randomly, the difficulty levels may vary. The program doesn’t check if the puzzle can be solved using only human logic.
Also the bigger the numbers you enter, the higher the levels and the more difficult it is for the program to generate a valid puzzle. Since the program was only a quick hack, I didn’t take the time to do any proper input validation. When you enter arguments to the program such as 10 10 99 (99 empty cells) the program isn’t going to find a valid puzzle. It does however try, which causes it to hang. Also generating large puzzles with many empty cells can take a (really) long time. Use Ctrl+C to interrupt the program.
Happy puzzle solving!