[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
|
Problem DescriptionBackground & TechniquesAnother puzzle from our 2013 "Brain Game" page-a-day calendar. I worked on this one for about 10 minutes before deciding that a 10 minute program would be more fun and more likely to guarantee a solution. To write it took more like 30 minutes, but it does find the two solutions in less than a second. We'll number the cells of a tic-tac-toe board 1 to 9 from left to right and top to bottom. We can then use the numbers to represent positions in a 9 digit binary number and interpret 1's as X's.
The program searches for solutions by generating the 9 binary digit
representation of all numbers all integers from 1('000000001') to 511
('111111111') and testing all of those which have six 1's. Programmer's Notes:The key to this 50 line program is our IntToBinaryString function contained in the DFFUtils unit. Calling the function passing integers up to 511 and specifying a minimum length of 9 makes it an easy matter to check all arrangements of six X's on the board. For example, 207 has binary representation 011001111 which has six "1" bits, but is not a solution since the bits in the positions 7, 8, and 9 represent three X's in the last row. Everything else is simple and well commented in the source code. Running/Exploring the Program
Suggestions for Further Explorations
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |