Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just for fun - Delphi code. 'shl' is left shift (&lt;&lt;), strings are one-based. Borders are added around the matrix as sentinels to simplify checks.</p> <p>Some additional comments: I use 6x6 matrix - 4x4 core with digits, and one-cell width outer border. 36 bits of Int64 are used as sentinels. Bit value of 1 denotes border or visited cell. Procedure StartTravel initiates path finding from some starting cell of core. Path finding goes like DFS (deep-first search), but interrupts when path length becomes 5.</p> <pre><code>const Directions: array[0..3] of Integer = (-1, -6, 1, 6); var Digits: string; Mask: Int64; i, j: Integer; procedure Travel(AFrom: Integer; Visited: Int64; Path: string); var i, Dir: Integer; NewMask: Int64; begin if Length(Path) = 5 then PrintOut(Path) else for i := 0 to 3 do begin Dir := Directions[i]; NewMask := 1 shl (AFrom + Dir); if (Visited and NewMask) = 0 then Travel(AFrom + Dir, Visited or NewMask, Path + Digits[AFrom + Dir + 1]); end; end; procedure Init; var i: Integer; begin Digits := '-------0123--7654--89AB--FEDC-------'; Mask := 0; for i := 1 to Length(Digits) do if Digits[i] = '-' then Mask := Mask or (1 shl (i - 1)); end; procedure StartTravel(Row, Col: Integer); var APos: Integer; begin APos := Row * 6 + Col + 7; Travel(APos, Mask or (1 shl APos), Digits[APos + 1]); end; begin Init; for i := 0 to 3 do for j := 0 to 3 do StartTravel(i, j); 432 combinations: 01234 01256 01254 0125A 01678 01652 01654 0165A 01698 0169A 0169E 07612 07652 .... CBADE CB456 CB452 CB45A CB432 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload