71.3k views
3 votes
Design a method for representing the state of a tic-tac-toe board in computer memory. can you fit your representation into three bytes?

2 Answers

4 votes

Answer:

A Tic-Tac-Toe board consist of 9 fields. Each field can take 3 states: Empty, Circle, Cross. To represent each state you need 2 bits: 00, 01, 10.

With two bits for each field, you can easily represent whole board in 3 bytes, by using two bits as each field, and each byte as row of board.

User Sleepyjames
by
6.5k points
6 votes
The combination of Xs,Os, and blanks will approximately be somewhere between 2048 and about 4048. The combination’s total is 19, 683, but since the Xs and Os number will always be equal or off by 1, many cases are eliminated. Thus, the board is represented in 11 or 12 bits.
User Duganets
by
7.1k points