Logic Programming – 3D Tic-Tac-Toe

This logic programming examples solves the problem of arranging X's and 0's on a three-dimensional Tic-Tac-Toe board.

This logic programming example solves the problem of arranging X’s and 0’s on a three-dimensional Tic-Tac-Toe board so as to minimize the number of completed lines or diagonals. It demonstrates the use of mixed-integer programming to capture simple logical constraints.

This is example 17 from the fifth edition of Model Building in Mathematical Programming, by H. Paul Williams on pages 272 and 327 – 328.

This modeling example is at the beginning level. We assume that you have some familiarity with Python and the Gurobi Python API, but you can hopefully pick up any missing concepts from the example.


Request a Gurobi Evaluation License or Free Academic License

Modeling examples are coded using the Gurobi Python API in Jupyter Notebook. In order to use the Jupyter Notebooks, you must have a Gurobi License. If you do not have a license, you can request an Evaluation License as a Commercial User or download a free license as an Academic User.


Commercial Users: Free Evaluation Version Academic Users: Free Academic Version



Access the Jupyter Notebook Modeling Example

Click on the button below to be directed to GitHub where you can download the repository for the 3D Tic-Tac-Toe Jupyter Notebook modeling example.


3D Tic-Tac-Toe


Contact Us

We’re happy to assist you. Please contact us using this form, and a Gurobi representative will get back to you shortly.

  • Free Consultations
  • General Inquiries
  • Gurobi Optimizer Questions

Can’t view the form? Please email us at sales@gurobi.com.

Thank you! The information has been submitted successfully.