Open EricCreusen opened 11 months ago
I'M GOING TO SHOW YOU AN EXAMPLE TO EXPLAIN THAT.
======== EASY EXAMPLE ========
WHEN YOU OPEN THE GAME, IT SHOWS:
↑ ↓ ←
↓ ← →
← → ↑
LET'S FOLLOW THE SOLUTION STEPS:
let
n
denote the number of arrows
so n
= 9
and m
denote number of possible orientations of arrows
(4
for easy and medium; 2
for hard; 6
for expert)
there are 4 possible orientations in easy mode: up/down/left/right
so m
= 4
give each arrow a number before the following steps
↑(1) ↓(2) ←(3)
↓(4) ←(5) →(6)
←(7) →(8) ↑(9)
define a column vector X
(size: n×1
)
each element X_i
represents the number of taps needed for i
-th arrow
since n
= 9, X is a column with length = 9
X
= [unknown unknown unknown unknown unknown unknown unknown unknown unknown]^T
the matrix X
is actually what we want to solve
and we will construct a equation to solve the matrix X
define a square matrix A
(size: n×n
)
element A_ij
is 1
if i
-th arrow is a neighbour of j
-th arrow, otherwise, A_ij
is 0
let's construct a zero sqaure matrix first (size: n×n
)
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
have a look at the game board
we gave a number to each arrow
(1) (2) (3)
(4) (5) (6)
(7) (8) (9)
1
is a neighbour of 1
, 2
, 4
and 5
fill in the coresponding cell with 1
[ 1 0 0 0 0 0 0 0 0 ]
[ 1 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 1 0 0 0 0 0 0 0 0 ]
[ 1 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
2
is a neighbour of 1
, 2
, 3
, 4
, 5
and 6
fill in the coresponding cell with 1
[ 1 1 0 0 0 0 0 0 0 ]
[ 1 1 0 0 0 0 0 0 0 ]
[ 0 1 0 0 0 0 0 0 0 ]
[ 1 1 0 0 0 0 0 0 0 ]
[ 1 1 0 0 0 0 0 0 0 ]
[ 0 1 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 0 ]
...
finally we have the matrix A
A
=
[1 1 0 1 1 0 0 0 0]
[1 1 1 1 1 1 0 0 0]
[0 1 1 0 1 1 0 0 0]
[1 1 0 1 1 0 1 1 0]
[1 1 1 1 1 1 1 1 1]
[0 1 1 0 1 1 0 1 1]
[0 0 0 1 1 0 1 1 0]
[0 0 0 1 1 1 1 1 1]
[0 0 0 0 1 1 0 1 1]
define a column vector B
(size: n×1
)
element B_i
represents the initial orientation of i
-th arrow
0
is up
; 1
is right
; 2
is down
; 3
is left;
have a look at the game board again:
↑(1) ↓(2) ←(3)
↓(4) ←(5) →(6)
←(7) →(8) ↑(9)
obviously the column vector B
is [ 0 2 3 2 3 1 3 1 0 ]^T
then the following equation should be satisfied:
A X + B = 0 (mod m)
solve for X
X = (A^-1)(-B) (mod m)
then X
= [3 2 1 2 1 1 1 1 1]^T
NOW IT'S TIME TO VERIFY THE ANSWER:
X
= [3 2 1 2 1 1 1 1 1]^T
IT MEANS YOU NEED TO:
↑(1) ↓(2) ←(3)
↓(4) ←(5) →(6)
←(7) →(8) ↑(9)
TYPE THE 1
-TH ARROW 3
TIMES
←(1) →(2) ←(3)
→(4) ↓(5) →(6)
←(7) →(8) ↑(9)
TYPE THE 2
-TH ARROW 2
TIMES
→(1) ←(2) →(3)
←(4) ↑(5) ←(6)
←(7) →(8) ↑(9)
TYPE THE 3
-TH ARROW 1
TIMES
→(1) ↑(2) ↓(3)
←(4) →(5) ↑(6)
←(7) →(8) ↑(9)
TYPE THE 4
-TH ARROW 2
TIMES
←(1) ↓(2) ↓(3)
→(4) ←(5) ↑(6)
→(7) ←(8) ↑(9)
TYPE THE 5
-TH ARROW 1
TIMES
↑(1) ←(2) ←(3)
↓(4) ↑(5) →(6)
↓(7) ↑(8) →(9)
TYPE THE 6
-TH ARROW 1
TIMES
↑(1) ↑(2) ↑(3)
↓(4) →(5) ↓(6)
↓(7) →(8) ↓(9)
TYPE THE 7
-TH ARROW 1
TIMES
↑(1) ↑(2) ↑(3)
←(4) ↓(5) ↓(6)
←(7) ↓(8) ↓(9)
TYPE THE 8
-TH ARROW 1
TIMES
↑(1) ↑(2) ↑(3)
↑(4) ←(5) ←(6)
↑(7) ←(8) ←(9)
TYPE THE 9
-TH ARROW 1
TIMES
↑(1) ↑(2) ↑(3)
↑(4) ↑(5) ↑(6)
↑(7) ↑(8) ↑(9)
!NICE! ======== EASY EXAMPLE END ========
FEEL FREE TO DISCUSS WITH ME IF YOU STILL HAVE QUESTIONS
I solved the easy problem by forming matrix B, and then just calling X=easy(B);
I want to similarly use X=hard(B) to solve the hard problem, but to do that I need to know in what order the arrows should be input into vector B.
In fact, any order is ok. (you can go from left to right top to bottom, or a spiral that unfolds counterclockwise, ... ...)
just keep the same order in all the matrixes(vectors) X
A
B
and:
element
A_ij
is1
ifi = j
ori
-th arrow is a neighbour ofj
-th arrow, otherwise,A_ij
is0
and if you want to solve to hard and expert problems:
Patch for Hard and Expert
follow the steps above, you will find that
A
is not invertible.actually the rank of matrix
A
is33
andn
is37
, which means thatA
is not a full rank matrix.solution: just remove
4
arrows of any edge of the hexagon fromA
,X
andB
, thenA
will be invertible and we never need to touch the4
ignored arrows.verify: use the unignored matrix
A
andB
andX
to verify the equation. actually the puzzle has a solution if and only if our solution is verified.
I was under the impression that the hard() and expert() function create the Matrix A for you. Is that not the case?
ahuahuahua you mean the python example code hard.py
.
essentially you can calculate the solution easily by following the readme.md
file. (this way you don't need to understand my coordinate system).
if you want to use the hard.py
, the order is for x in range(1-N, N) for y in range(1-N, N) for z in range(1-N, N) if x+y+z == 0
where N
is 4
, (the x-axis, y-axis and z-axis are the lines connecting the midpoints of the three opposite sides of the hexagon. they form an angle of 120 degrees with each other.):
[(-3, 0, 3), (-3, 1, 2), (-3, 2, 1), (-3, 3, 0), (-2, -1, 3), (-2, 0, 2), (-2, 1, 1), (-2, 2, 0), (-2, 3, -1), (-1, -2, 3), (-1, -1, 2), (-1, 0, 1), (-1, 1, 0), (-1, 2, -1), (-1, 3, -2), (0, -3, 3), (0, -2, 2), (0, -1, 1), (0, 0, 0), (0, 1, -1), (0, 2, -2), (0, 3, -3), (1, -3, 2), (1, -2, 1), (1, -1, 0), (1, 0, -1), (1, 1, -2), (1, 2, -3), (2, -3, 1), (2, -2, 0), (2, -1, -1), (2, 0, -2), (2, 1, -3), (3, -3, 0), (3, -2, -1), (3, -1, -2), (3, 0, -3)]
an example of my three-dimensional coordinate system on the plane:
It's not clear in what order the entries in matrix B should be input for the hard or expert puzzles. I tried a few different ways, but kept getting incorrect solutions so I must be doing it wrong.