Mathematical Solution To Triangular Sudoku Using Monte Carlo Methods

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Mathematical Solution to Triangular Sudoku Using

Monte Carlo Methods


Jacob H Lashover
March 25, 2020
Baton Rouge, Louisiana

Abstract: A challenging triangular Sudoku puzzle has been found on


of all places, a box of DOTS candy, presumably to be solved by the
candy purchaser—possibly a child. Upon close inspection, this
innocuous puzzle turned out to be a bit difficult for the average DOTS
chewer to handle.

1
Key Words: Constraints, mathematical solution, Sudoku, QB64 computer
language, simultaneous equations, Monte Carlo methods, and EXCEL Solver.

Problem Analysis:
Assigning variable names to each position starting from the lower left
in a clockwise manner, we have X1, X2, X3, X4, X5, X6, X7, X8, and
X9 where X2 = 4, X5 = 2, and X8 = 5. The unknown X’s must be
positive integers varying from 1 to 9 with no number used more than
once. The sum of the digits for each side must be equal and can be
written as below:
Sum1 = X1 + X2 + X3 + X4
Sum2 = X4 + X5 + X6 + X7
Sum3 = X7 + X8 + X9 + X1
The values of Sum1, Sum2, and Sum3 are unknown while it can be
inferred that the sum of all 9 digits must equal 45. With X2, X5, and X8
known, there are 6 unknown digits and one value of Sum1, Sum2, and
Sum3. The equation for the sum of all digits would be as follows:
Sum of digits = 45 = X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9

Discussion of Solution:
Use of Monte Carlo methods and the easily understood QB64
computer language leads to quick solution. Since three solutions were
found, the puzzle cannot be considered a true Sudoku whereby definition
only one solution exists. The reader is encouraged to try other solutions
using packaged software such as EXCEL Solver which becomes

2
complicated when the constraint “All Different” is attempted to be
invoked.
As shown, the QB64 code does not have to be efficient as computer
speed and memory have become so inexpensive. QB64 can be
downloaded for free at QB64.org. Get QB64 v 1.4, a modern extended
BASIC programming language that retains QBasic/QuickBasic 4.5
compatibility and compiles native binaries for Windows, Linux, and
macOS. No relationship between DOTS, the candy product, and this
report are intended. With tongue in cheek, one might say, “the dots have
been connected”. C++ programmers should also note the casual use of
the dreaded “GOTO” statement.
QB64 Computer Solution:
REM DOTS.BAS 03/25/2020 JH LASHOVER
REM USE NUMBERS 1 - 9 SO EACH SIDE OF THE TRIANGLE ADDS UP
TO THE SAME AMOUNT.
REM DO NOT USE A NUMBER MORE THAN ONCE.
REM X4
REM
REM X3 2
REM
REM 4 X6
REM
REM X1 X9 5 X7
RANDOMIZE TIMER
DIM X (-10 TO 10)
FOR J = 1 TO 5000
FOR I = 1 TO 9

3
IF I = 2 THEN X(I) = 4: GOTO 10
IF I = 5 THEN X(I) = 2: GOTO 10
IF I = 8 THEN X(I) = 5: GOTO 10
5 X(I) = INT (9 * RND) + 1
IF X(I) = 2 OR X(I) = 5 OR X(I) = 4 THEN GOTO 5
IF X(I) = X (I - 1) THEN GOTO 5
IF X(I) = X (I - 2) THEN GOTO 5
IF X(I) = X (I - 3) THEN GOTO 5
IF X(I) = X (I - 4) THEN GOTO 5
IF X(I) = X (I - 5) THEN GOTO 5
IF X(I) = X (I - 6) THEN GOTO 5
IF X(I) = X (I - 7) THEN GOTO 5
IF X(I) = X (I - 8) THEN GOTO 5
10 PRINT I; X(I)
NEXT I
'INPUT " PRESS ENTER TO CONTINUE", YES
SUM1 = X (1) + X (2) + X (3) + X (4)
SUM2 = X (4) + X (5) + X (6) + X (7)
SUM3 = X (7) + X (8) + X (9) + X (1)
PRINT SUM1, SUM2, SUM3
IF SUM1 <> SUM2 THEN GOTO 17
IF SUM2 = SUM3 THEN PRINT " NUMBER OF TRIES= "; J; "PROBLEM IS
SOLVED!": GOTO 20
17 NEXT J
20 INPUT " PRESS ENTER TO CONTINUE", YES
END

4
Solution No. 1 Sum1 = 21 Sum2 = 21 Sum3 = 21
1 6
2 4
3 8
4 3
5 2
6 7
7 9
8 5
9 1
21 21 21
Number of tries = 713 Problem is solved!

Solution No 2 Sum1 = 23 Sum2 = 23 Sum3 = 23


1 9
2 4
3 3
4 7
5 2
6 6
7 8
8 5
9 1
23 23 23
Number of tries = 71 Problem is solved!

5
Solution No 3 Sum1 = 21 Sum2 =21 Sum3 = 21

1 8
2 4
3 6
4 3
5 2
6 9
7 7
8 5
9 1
21 21 21
Number of tries = 365 Problem is solved!

Bibliography:
1. Lashover, J. H. (2012, November 12). Monte Carlo Marching,
Academia.edu and ResearchGate.net.
2. Lashover, J. H. (2015, September 17). Mathematical Solution to
Sudoku Using Monte Carlo Marching, Academia.edu and
ResearchGate.net.

You might also like