Author |
Topic |
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-03 : 07:39:26
|
OK, Sam.... How about to run chess knight over allchess board cells? Below, in bold, the 4 possible first moves:56 57 58 59 60 61 62 6348 49 50 51 52 53 54 5540 41 42 43 44 45 46 4732 33 34 35 36 37 38 3924 25 26 27 28 29 30 3116 17 18 19 20 21 22 2308 09 10 11 12 13 14 1500 01 02 03 04 05 06 07And this is a sample of failed chain of moves:17 00 10 04 14 20 03 09 19 02 08 18 01 11 05 1521 06 12 22 07 13 23 29 35 25 40 34 24 41 26 1633 27 37 31 46 36 30 45 39 54 44 50 60 43 28 3855 61 51 57 42 32 49 59 53 47 62 52 58 48 xx xx |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-02-03 : 09:20:35
|
Did ya buy a book on SQL puzzles or did your manager bug you today? This reeks of a revolt against real work. Only a twisted mind would publish such a question.I don't think it's solvable.Nope.Can't be solved.Got to go now. |
 |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-02-03 : 09:22:09
|
I got a solution with a small change to the problem.I used a rook. |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-03 : 14:50:07
|
LOL, Sam. I wish you knew how many "problems" I keep inmind simultaneosly. OK, I just got (already at home) my 1stHamilton circuit for the knight on the standard chess board.Not easy job I would say. True, this is old good VB..........00 10 04 14 20 03 09 19 02 08 18 01 11 05 15 2106 12 22 07 13 23 29 35 25 40 34 24 41 56 50 3316 26 32 49 59 44 38 28 43 60 54 39 45 55 61 5157 42 48 58 52 62 47 30 36 53 63 46 31 37 27 17Sub hamC()Const n = 63, w = 8Dim s1(n), s2(n), i, j, k, c1, c2, f, ffFor j = 0 To ns2(j) = j: s1(j) = -1Nexts2(0) = -1: s1(0) = 0: c1 = 0: c2 = -1: i = 0While i < nf = 0For k = 0 To nIf s2(k) > -1 And s2(k) > c2 ThenIf ok(c1, s2(k), w) ThenIf zorg(s2, s2(k), c2, w) Theni = i + 1: s1(i) = s2(k): s2(k) = -1: c1 = s1(i): f = 1If c2 <> -1 Thens2(c2) = c2: c2 = -1End IfExit ForEnd IfEnd IfEnd IfNext kIf f = 0 ThenIf c2 <> -1 Thens2(c2) = c2End Ifc2 = s1(i): s1(i) = -1: i = i - 1: c1 = s1(i)End IfWendFor k = 0 To nff = ff & Right("0" & CStr(s1(k)), 2) & _IIf((k + 1) Mod (2 * w) = 0, vbCrLf, " ")NextDebug.Print ffEnd SubFunction zorg(ByVal s, ByVal c, ByVal d, ByVal ww) As Booleanzorg = Falses(0) = 0: s(c) = cIf d > -1 Thens(d) = dEnd IfDim a, b, gFor Each a In sIf a > -1 And a <> 0 And a <> c Theng = 0For Each b In sIf b > -1 And ok(a, b, ww) Theng = g + 1If g > 1 ThenExit ForEnd IfEnd IfNextIf g < 2 ThenExit FunctionEnd IfEnd IfNextzorg = TrueEnd FunctionFunction ok(ByVal p, ByVal q, ByVal r) As Booleanok = FalseIf ((Abs(p \ r - q \ r) = 1 And Abs(p Mod r - q Mod r) = 2) Or _(Abs(p \ r - q \ r) = 2 And Abs(p Mod r - q Mod r) = 1)) Thenok = TrueEnd IfEnd Function |
 |
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2004-02-04 : 06:08:45
|
Setup:CREATE TABLE MovesA (s1 tinyint NOT NULL, s2 tinyint NOT NULL, PRIMARY KEY (s1, s2))INSERT INTO MovesASELECT A.n, B.nFROM ( SELECT n, n % 8 AS x, n / 8 AS y FROM Numbers WHERE n BETWEEN 0 AND 63 ) AS AINNER JOIN ( SELECT n, n % 8 AS x, n / 8 AS y FROM Numbers WHERE n BETWEEN 0 AND 63 ) AS BON (ABS(A.x - B.x) = 2 AND ABS(A.y - B.y) = 1) OR (ABS(A.x - B.x) = 1 AND ABS(A.y - B.y) = 2)WHERE (A.x + A.y) % 2 = 0CREATE TABLE MovesB (s1 tinyint NOT NULL, s2 tinyint NOT NULL, PRIMARY KEY (s1, s2))INSERT INTO MovesBSELECT A.n, B.nFROM ( SELECT n, n % 8 AS x, n / 8 AS y FROM Numbers WHERE n BETWEEN 0 AND 63 ) AS AINNER JOIN ( SELECT n, n % 8 AS x, n / 8 AS y FROM Numbers WHERE n BETWEEN 0 AND 63 ) AS BON (ABS(A.x - B.x) = 2 AND ABS(A.y - B.y) = 1) OR (ABS(A.x - B.x) = 1 AND ABS(A.y - B.y) = 2)WHERE (A.x + A.y) % 2 = 1 Find the first one:SELECT TOP 1 *FROM MovesA AS M01INNER JOIN MovesB AS M02 ON M01.s2 = M02.s1INNER JOIN MovesA AS M03 ON M02.s2 = M03.s1INNER JOIN MovesB AS M04 ON M03.s2 = M04.s1INNER JOIN MovesA AS M05 ON M04.s2 = M05.s1INNER JOIN MovesB AS M06 ON M05.s2 = M06.s1INNER JOIN MovesA AS M07 ON M06.s2 = M07.s1INNER JOIN MovesB AS M08 ON M07.s2 = M08.s1INNER JOIN MovesA AS M09 ON M08.s2 = M09.s1INNER JOIN MovesB AS M10 ON M09.s2 = M10.s1INNER JOIN MovesA AS M11 ON M10.s2 = M11.s1INNER JOIN MovesB AS M12 ON M11.s2 = M12.s1INNER JOIN MovesA AS M13 ON M12.s2 = M13.s1INNER JOIN MovesB AS M14 ON M13.s2 = M14.s1INNER JOIN MovesA AS M15 ON M14.s2 = M15.s1INNER JOIN MovesB AS M16 ON M15.s2 = M16.s1INNER JOIN MovesA AS M17 ON M16.s2 = M17.s1INNER JOIN MovesB AS M18 ON M17.s2 = M18.s1INNER JOIN MovesA AS M19 ON M18.s2 = M19.s1INNER JOIN MovesB AS M20 ON M19.s2 = M20.s1INNER JOIN MovesA AS M21 ON M20.s2 = M21.s1INNER JOIN MovesB AS M22 ON M21.s2 = M22.s1INNER JOIN MovesA AS M23 ON M22.s2 = M23.s1INNER JOIN MovesB AS M24 ON M23.s2 = M24.s1INNER JOIN MovesA AS M25 ON M24.s2 = M25.s1INNER JOIN MovesB AS M26 ON M25.s2 = M26.s1INNER JOIN MovesA AS M27 ON M26.s2 = M27.s1INNER JOIN MovesB AS M28 ON M27.s2 = M28.s1INNER JOIN MovesA AS M29 ON M28.s2 = M29.s1INNER JOIN MovesB AS M30 ON M29.s2 = M30.s1INNER JOIN MovesA AS M31 ON M30.s2 = M31.s1INNER JOIN MovesB AS M32 ON M31.s2 = M32.s1INNER JOIN MovesA AS M33 ON M32.s2 = M33.s1INNER JOIN MovesB AS M34 ON M33.s2 = M34.s1INNER JOIN MovesA AS M35 ON M34.s2 = M35.s1INNER JOIN MovesB AS M36 ON M35.s2 = M36.s1INNER JOIN MovesA AS M37 ON M36.s2 = M37.s1INNER JOIN MovesB AS M38 ON M37.s2 = M38.s1INNER JOIN MovesA AS M39 ON M38.s2 = M39.s1INNER JOIN MovesB AS M40 ON M39.s2 = M40.s1INNER JOIN MovesA AS M41 ON M40.s2 = M41.s1INNER JOIN MovesB AS M42 ON M41.s2 = M42.s1INNER JOIN MovesA AS M43 ON M42.s2 = M43.s1INNER JOIN MovesB AS M44 ON M43.s2 = M44.s1INNER JOIN MovesA AS M45 ON M44.s2 = M45.s1INNER JOIN MovesB AS M46 ON M45.s2 = M46.s1INNER JOIN MovesA AS M47 ON M46.s2 = M47.s1INNER JOIN MovesB AS M48 ON M47.s2 = M48.s1INNER JOIN MovesA AS M49 ON M48.s2 = M49.s1INNER JOIN MovesB AS M50 ON M49.s2 = M50.s1INNER JOIN MovesA AS M51 ON M50.s2 = M51.s1INNER JOIN MovesB AS M52 ON M51.s2 = M52.s1INNER JOIN MovesA AS M53 ON M52.s2 = M53.s1INNER JOIN MovesB AS M54 ON M53.s2 = M54.s1INNER JOIN MovesA AS M55 ON M54.s2 = M55.s1INNER JOIN MovesB AS M56 ON M55.s2 = M56.s1INNER JOIN MovesA AS M57 ON M56.s2 = M57.s1INNER JOIN MovesB AS M58 ON M57.s2 = M58.s1INNER JOIN MovesA AS M59 ON M58.s2 = M59.s1INNER JOIN MovesB AS M60 ON M59.s2 = M60.s1INNER JOIN MovesA AS M61 ON M60.s2 = M61.s1INNER JOIN MovesB AS M62 ON M61.s2 = M62.s1INNER JOIN MovesA AS M63 ON M62.s2 = M63.s1INNER JOIN MovesB AS M64 ON M63.s2 = M64.s1WHERE M01.s1 = 0 AND M64.s2 = 0AND M03.s1 NOT IN (M01.s1)AND M04.s1 NOT IN (M02.s1)AND M05.s1 NOT IN (M01.s1,M03.s1)AND M06.s1 NOT IN (M02.s1,M04.s1)AND M07.s1 NOT IN (M01.s1,M03.s1,M05.s1)AND M08.s1 NOT IN (M02.s1,M04.s1,M06.s1)AND M09.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1)AND M10.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1)AND M11.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1)AND M12.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1)AND M13.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1)AND M14.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1)AND M15.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1)AND M16.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1)AND M17.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1)AND M18.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1)AND M19.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1)AND M20.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1)AND M21.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1)AND M22.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1)AND M23.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1)AND M24.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1)AND M25.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1)AND M26.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1)AND M27.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1)AND M28.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1)AND M29.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1)AND M30.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1)AND M31.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1)AND M32.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1)AND M33.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1)AND M34.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1)AND M35.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1)AND M36.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1)AND M37.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1)AND M38.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1)AND M39.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1)AND M40.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1)AND M41.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1)AND M42.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1)AND M43.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1)AND M44.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1)AND M45.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1)AND M46.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1)AND M47.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1)AND M48.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1)AND M49.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1,M47.s1)AND M50.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1,M48.s1)AND M51.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1,M47.s1,M49.s1)AND M52.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1,M48.s1,M50.s1)AND M53.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1,M47.s1,M49.s1,M51.s1)AND M54.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1,M48.s1,M50.s1,M52.s1)AND M55.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1,M47.s1,M49.s1,M51.s1,M53.s1)AND M56.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1,M48.s1,M50.s1,M52.s1,M54.s1)AND M57.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1,M47.s1,M49.s1,M51.s1,M53.s1,M55.s1)AND M58.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1,M48.s1,M50.s1,M52.s1,M54.s1,M56.s1)AND M59.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1,M47.s1,M49.s1,M51.s1,M53.s1,M55.s1,M57.s1)AND M60.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1,M48.s1,M50.s1,M52.s1,M54.s1,M56.s1,M58.s1)AND M61.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1,M47.s1,M49.s1,M51.s1,M53.s1,M55.s1,M57.s1,M59.s1)AND M62.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1,M48.s1,M50.s1,M52.s1,M54.s1,M56.s1,M58.s1,M60.s1)AND M63.s1 NOT IN (M01.s1,M03.s1,M05.s1,M07.s1,M09.s1,M11.s1,M13.s1,M15.s1,M17.s1,M19.s1,M21.s1,M23.s1,M25.s1,M27.s1,M29.s1,M31.s1,M33.s1,M35.s1,M37.s1,M39.s1,M41.s1,M43.s1,M45.s1,M47.s1,M49.s1,M51.s1,M53.s1,M55.s1,M57.s1,M59.s1,M61.s1)AND M64.s1 NOT IN (M02.s1,M04.s1,M06.s1,M08.s1,M10.s1,M12.s1,M14.s1,M16.s1,M18.s1,M20.s1,M22.s1,M24.s1,M26.s1,M28.s1,M30.s1,M32.s1,M34.s1,M36.s1,M38.s1,M40.s1,M42.s1,M44.s1,M46.s1,M48.s1,M50.s1,M52.s1,M54.s1,M56.s1,M58.s1,M60.s1,M62.s1) Only joking![Edit: Oops! Had the join conditions the wrong way round] |
 |
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2004-02-04 : 06:39:47
|
quote: Originally posted by StoadOK, I just got (already at home) my 1stHamilton circuit for the knight on the standard chess board.
1 down, 13267364410531 to go! |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-02-04 : 07:27:32
|
Don't know if this will work but should be something like it.It doesn't avoid things it has already done just tries random moves each time.set nocount oncreate table #a (i int, j int)declare @i int, @j intselect @i = 0, @j = 1while @i < 8begin select @i = @i + 1 insert #a select @i, @jendwhile @j < 8begin select @j = @j + 1 insert #a select i, @j from #a where j = 1endselect * into #b from #aselect @i = 1, @j = 1create table #moves (i int, j int, id int identity)insert #moves select 2,-1 insert #moves select 2,1insert #moves select 1,2insert #moves select -1,2insert #moves select -2,1insert #moves select -2,-1insert #moves select -1,-2insert #moves select 1,-2create table #MoveDone (i int, j int, id int identity)-- now lets try 1000 times - selecting random moves each timeset nocount ondeclare @runs int, @Best intselect @runs = 1000, @Best = 0while @runs > 0 and 64 > (select max(id) from #MoveDone)begin select @runs = @runs - 1 truncate table #MoveDone delete #b insert #b select * from #a declare @i int, @j int select @i = 1, @j = 1 declare @MoveID int, @MoveAttempt int select @MoveAttempt = 0 while @MoveAttempt < 9 and 64 > (select count(*) from #MoveDone) begin select @MoveAttempt = 0 select @MoveID = convert(int,rand() * 8 + 1) while @MoveAttempt < 9 and not exists (select * from #b, #moves where #b.i = @i + #moves.i and #b.j = @j + #moves.j and #moves.id = @MoveID) begin select @MoveAttempt = @MoveAttempt + 1 , @MoveID = case when @MoveID = 8 then 1 else @MoveID + 1 end end if @MoveAttempt < 9 begin select @i = @i + i, @j = @j + j from #Moves where id = @MoveID delete #b where i = @i and j = @j insert #MoveDone select @i, @j end end if @Best < (select max(id) from #MoveDone) select @Best = max(id) from #MoveDoneendselect bestattempt = @Bestsecond run got 63 moves==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-04 : 07:56:25
|
lol >> SQL XTreme....quote: 1 down, 13267364410531 to go!
No problem:00 10 04 14 20 03 09 19 02 08 18 01 11 05 15 2106 12 22 07 13 23 29 35 25 40 34 24 41 56 50 3316 26 32 49 59 44 38 28 43 60 54 39 45 55 61 5157 42 48 58 52 62 47 30 36 53 63 46 31 37 27 1700 10 04 14 20 03 09 19 02 08 18 01 11 05 15 2106 12 22 07 13 23 29 35 25 40 34 24 41 56 50 3316 26 32 49 59 44 54 39 45 60 43 28 38 55 61 5157 42 48 58 52 62 47 30 36 53 63 46 31 37 27 1700 10 04 14 20 03 09 19 02 08 18 01 11 05 15 2106 12 22 07 13 23 29 35 25 40 34 24 41 56 50 3316 26 32 49 59 44 61 55 38 28 43 60 54 39 45 3036 51 57 42 48 58 52 62 47 53 63 46 31 37 27 1700 10 04 14 20 03 09 19 02 08 18 01 11 05 15 2106 12 22 07 13 23 29 35 25 40 34 24 41 56 50 3316 26 32 49 59 44 61 55 38 28 43 60 54 39 45 3047 62 52 58 48 42 57 51 36 53 63 46 31 37 27 1700 10 04 14 20 03 09 19 02 08 18 01 11 05 15 2106 12 22 07 13 23 29 35 25 40 34 24 41 56 50 3316 26 32 49 59 44 61 55 38 28 43 60 54 39 45 5157 42 48 58 52 62 47 30 36 53 63 46 31 37 27 17 |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-02-04 : 08:17:53
|
Does the square you start at count or do you have to return to it?From the example I thought you had to return but from this you don't.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-02-04 : 08:23:46
|
Counting the start position as taken quickly gives (hope it's right)(just adddelete #b where i = @i and j = @jinsert #MoveDone select @i, @jafterselect @i = 1, @j = 1)i j id ----------- ----------- ----------- 1 1 13 2 25 1 37 2 48 4 57 6 68 8 76 7 84 8 92 7 101 5 112 3 123 1 135 2 147 1 158 3 167 5 178 7 186 8 194 7 202 8 213 6 221 7 233 8 242 6 251 8 263 7 271 6 282 4 291 2 303 3 312 1 321 3 333 4 344 6 352 5 364 4 376 3 385 5 394 3 406 2 418 1 427 3 436 5 447 7 455 8 466 6 478 5 486 4 495 6 503 5 511 4 522 2 534 1 545 3 554 5 565 7 577 8 588 6 597 4 608 2 616 1 624 2 635 4 64==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-04 : 09:48:21
|
Not sure what exactly you mean, Nigel. My enumeration ofthe board squares is as follows:56 57 58 59 60 61 62 6348 49 50 51 52 53 54 5540 41 42 43 44 45 46 4732 33 34 35 36 37 38 3924 25 26 27 28 29 30 3116 17 18 19 20 21 22 2308 09 10 11 12 13 14 1500 01 02 03 04 05 06 07So, the result00 10 04 14 20 03 09 19 02 08 18 01 11 05 15 2106 12 22 07 .. .. .. .. and so on .. .. .. .. .. .. .. 17meaning is pretty obvious. Plus, the condition to findcircuit is embedded into my code. That is whyall my chains of moves end up with square 17.Edit: see nr's sample of NON-circuit path in the previous post. |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-02-04 : 10:08:30
|
It was the first four possible moves you gave in the question that confused me.Guess it was 3 moves and you started from 17.Mine starts from a corner but that could be randomised too.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-04 : 14:24:16
|
Nice (and working) idea - "to randomize it". |
 |
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2004-02-04 : 15:45:11
|
To be honest, I'm finding Nigel's code a bit difficult to understand -- too many random numbers! Is it (deliberately or accidentally) using Warnsdorff's algorithm?http://mathworld.wolfram.com/KnightsTour.htmlHere's my attempt at Warnsdorff: it seems generate a path about 98% of the time, but a circuit only about 2%.CREATE TABLE Moves( s1 tinyint NOT NULL, s2 tinyint NOT NULL, PRIMARY KEY (s1,s2))CREATE TABLE Squares(i int IDENTITY(1,1) PRIMARY KEY, s tinyint NOT NULL UNIQUE, ct int NOT NULL)INSERT INTO MovesSELECT N1.n, N2.nFROM Numbers AS N1INNER JOIN Numbers AS N2ON (ABS(N1.n %8 - N2.n%8) = 2 AND ABS(N1.n /8 - N2.n/8) = 1)OR (ABS(N1.n %8 - N2.n%8) = 1 AND ABS(N1.n /8 - N2.n/8) = 2)WHERE N1.n BETWEEN 0 AND 63 AND N2.n BETWEEN 0 AND 63DECLARE @i intSET @i = 0WHILE @i < 100 BEGIN SET @i = @i + 1 SET NOCOUNT ON TRUNCATE TABLE Squares INSERT INTO Squares (s, ct) SELECT TOP 1 s1, 2 FROM Moves GROUP BY s1 ORDER BY COUNT(*) WHILE 1=1 BEGIN INSERT INTO Squares (s, ct) SELECT TOP 1 s, ct FROM ( SELECT TOP 1 WITH TIES s2 AS s, ( SELECT COUNT(*) FROM Moves AS B WHERE A.s2 = B.s1 AND s2 NOT IN (SELECT s FROM Squares) ) AS ct FROM Moves AS A WHERE s1 = (SELECT TOP 1 s FROM Squares ORDER BY i DESC) AND s2 NOT IN (SELECT s FROM Squares) ORDER BY ct ) AS A ORDER BY NEWID() IF @@ROWCOUNT = 0 BREAK END SET NOCOUNT OFF IF (SELECT COUNT(*) FROM Squares) = 64 AND EXISTS( SELECT * FROM Moves WHERE s1 = (SELECT TOP 1 s FROM Squares ORDER BY i ASC) AND s2 = (SELECT TOP 1 s FROM Squares ORDER BY i DESC)) BEGIN SELECT i, s%8, s/8, ct FROM Squares ORDER BY i ENDEND |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-02-04 : 16:32:06
|
I don't know anything about the theory of this.It just picks a random move - if that square isn't available it tries the other 7 in turn and takes the first that is and keeps going until it can't move.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2004-02-05 : 12:27:13
|
I looked for the solution to the Knights problem on the web, and found that the problem requires that a knight doesn't land on the same place twice.It may be that there are some starting points that cannot succeed. |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-05 : 15:00:18
|
>> A. F.Great (but I can test it only tomorrow - how fast it produces circuits).Plus, I don't see so far where in the code a backtracking part. I supposethere is no any. Think the ORDER BY NEWID() took its place (with"intermittent" success while in the outer "while" loop). Not sure but I believethat Warnsdorff meant "backtracking" + "playing with the successors". I willtry to use his idea in my code - which is extremely plain: "backtracking" +"checking (zorg() function) before each move will (or not) some not-visited"remote" square be left deadlocked (i.e., left with less than 2 "exits" from it)".>>nrquote: I don't know anything about the theory of this.
In fact there is no any theory of this. Only some fuzzy euristics.>>SamCquote: It may be that there are some starting points that cannot succeed.
Do you mean succeed with circuits? (lol, it's just a stoad crack) |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-06 : 04:06:30
|
>> Arnold Fribble <<Works fine and pretty fast, however in vb it is about 10 times faster.PS Here I mean only hamilton circuits. |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-06 : 08:35:22
|
The WITH TIES + ORDER BY NEWID() .... it's very clever I think. |
 |
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2004-02-08 : 18:16:10
|
Ahh Chess... My pet SQL project at the moment.....I won't bore you with the details but the query below shows every possible Knight move on the board..Select A.Square, B.Squarefrom RealBoard A CROSS JOIN RealBoard BWHERE dbo.KnightValidMove(A.Square, B.Square) = 1 It returns 336 possible moves.. Can anyone confirm that?DavidM"SQL-3 is an abomination.." |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-02-08 : 20:22:27
|
Yep. that's what I got.select x as StartX, y as StartY, x + (H.Squares * Horiz.Mult) as EndX, y + ((3- H.Squares) * Vert.Mult) as EndYfrom(select 1 as Mult union select -1 as Mult) Horizcross join(select 1 as Mult union select -1 as Mult) Vertcross join(select 1 as Squares union select 2) Hcross join(select 1 as X union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8) Across join(select 1 as Y union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8) Bwhere x + (H.Squares * Horiz.Mult) between 1 and 8 AND y + ((3-H.Squares) * Vert.Mult) between 1 and 8 - Jeff |
 |
|
Next Page
|
|
|