Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ClearAll["Global`*"];
- ks = {{-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {1, -2}, {1, 2}, {2, -1}, {2, 1}};
- chCorners[kp_] :=
- Switch[kp,
- {2, 6}, {{2, 6}, {1, 8}, {3, 7}},
- {3, 7}, {{3, 7}, {1, 8}, {2, 6}},
- {6, 2}, {{6, 2}, {8, 1}, {7, 3}},
- {7, 3}, {{7, 3}, {8, 1}, {6, 2}},
- {6, 7}, {{6, 7}, {8, 8}, {7, 6}},
- {7, 6}, {{7, 6}, {8, 8}, {6, 7}},
- _, {kp}];
- tryNext[p1_, p2_] :=
- Module[{path1 = p1, path2 = p2, lp, ns1, ns2, np1, np2},
- count = count + 1;
- ns1 = Table[Last[path1] + ks[[i]], {i, 1, 8}];
- ns2 = Table[Last[path2] + ks[[j]], {j, 1, 8}];
- If[count == 984, Print[Length[path2], " a ", path2]];
- Do[
- If[
- (! done) && (0 < ns1[[i, 1]] < 9) && (0 < ns1[[i, 2]] < 9) &&
- ! (MemberQ[path1, ns1[[i]]] || MemberQ[path2, ns1[[i]]]),
- np1 = Join[path1, chCorners[ns1[[i]]]];
- lp = Length[np1] + Length[path2] - 1;
- If[(count == 984), Print[Length[path2], " b ", path2]];
- done = (lp == 64) && MemberQ[ks, Last[np1] - Last[path2]];
- If[lp < 64,
- Do[
- If[
- (! done) && (0 < ns2[[j, 1]] < 9) && (0 < ns2[[j, 2]] < 9) &&
- ! (MemberQ[np1, ns2[[j]]] || MemberQ[path2, ns2[[j]]]),
- np2 = Join[path2, chCorners[ns2[[j]]]];
- tryNext[np1, np2]],
- {j, 1, 8}]]],
- {i, 1, 8}]];
- done = False;
- count = 0;
- (* Starting two paths from lower left corned, {1,1} *)
- tryNext[{{1, 1}, {2, 3}}, {{1, 1}, {3, 2}}];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement