SQL Tic‑Tac‑Toe Challenge: Generate Endgame Boards and Find Forced Wins
The ITPUB community revived its SQL Database Programming Contest, outlining judges, prize tiers, and detailed rules, then presenting two Oracle‑SQL puzzles—one to generate every possible tic‑tac‑toe endgame board and another to determine a forced winning strategy for a given board—plus an optional extension for larger m,n,k games.
ITPUB SQL Database Programming Contest
The ITPUB community organized the second "Shengtou Media Cup" SQL Database Programming Contest, inviting participants to submit solutions within a specified time window and offering a multi‑tier prize structure, including cash vouchers, conference tickets, and exclusive badges.
Judging Panel
Judges include senior Oracle forum moderators and experienced database engineers such as Lu Tao, Su Xuhui, and Ding Jun, each with extensive backgrounds in C/C++, Oracle development, and system optimization.
Contest Rules and Scoring
Process : Publish problem statements and answer window, collect submissions, anonymize and renumber them, then judges evaluate within ten days and provide feedback.
Evaluation Criteria :
Readability and simplicity of a single‑SQL solution (20 points)
Problem‑solving approach (20 points)
Correctness and completeness (40 points)
Performance (20 points)
Prize Structure
First prize: ¥500 JD gift card, conference ticket, and "ITPUB SQL Database Programming Master" badge.
Second prize: ¥300 JD gift card, conference ticket, and badge.
Third prize: ¥200 JD gift card, conference ticket, and badge.
Fourth prize: ¥100 JD gift card, conference ticket, and badge.
Participation prize: commemorative hoodie and participation badge for every entrant.
Problem 1 – Generate All Endgame Boards (100 points)
Participants must create a table
CREATE TABLE TICTACTOE (MOVES VARCHAR2(9) PRIMARY KEY, BOARD VARCHAR2(9), WINNER VARCHAR2(1));and write a single SQL statement that inserts every possible terminal tic‑tac‑toe game (including all move orders) together with the final board layout and the winner (X, O, or D for draw). The solution must run on Oracle 10g or higher, avoid PL/SQL functions inside WITH clauses, and use LISTAGG for string concatenation instead of the undocumented WM_CONCAT. A download link for Oracle Express is provided for those without a test environment.
Problem 2 – Forced Win Detection (100 points)
Given a valid board state (e.g., V_BOARD='X-0------'), write an SQL query that determines which player has a forced winning strategy and the maximum number of additional moves the winner needs to guarantee victory (output format: X3 for X winning in three more moves, O0 if O has already won, or D if no forced win exists). The query must be executed in SQLPLUS after declaring a variable VAR V_BOARD VARCHAR2(9) and assigning the board string.
Additional Challenge
Extend the second problem to handle the general m×n×k game (e.g., 15×15×5 for Gomoku). Solutions that work for any board size ≥3 earn an extra ten points.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
