Binary-coded Ternary
Representing Tic-tac-toe in ternary form, and efficiently generating all possible boards. - yduf
Rather than doing binary to ternary number conversion (implying divide and mod by 3), we can directly count in binary-coded ternary form.
Ternary Increment
My own code to increment from 1 to N in binary-coded ternary representation. Trick is to use the binary + for handling carry over, by first allowing propagation when it will be needed and then masking spurious bits.
TODO: would it allow general addition operation (ternary) + binary operand ?
Notes: it still requires 2*9=18bits to represent Tic-tac-toe state in Binary-Coded Ternary (contrary to the sample code above which use 16bits integer).
Resources
Written on June 12, 2021, Last update on November 21, 2021
ternary
bits
math
c++
tic-tac-toe