All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Logic
Extended Knight's Tour (Posted on 2008-07-10) Difficulty: 4 of 5
Our valiant knight is about to embark on a longer tour than usual, but he doesn't mind, because there is a lovely young maid waiting at his destination.

The Knight enters the upper chess board at number 1, visiting each cell, just once, in numerical order. When he reaches number 64, he makes another Knight's Move to number 65 in the lower board. He then proceeds in the same manner until he reaches his destination at number 128.

Can you recreate the tour?
               
               
               
               
          6    
               
               
               
               
               
      128        
               
               
               
               
               
KEY:
Blue = cube numbers (1, 8, 27,64 and 125)
Green = squares which are not cubes (4, 9, 16, 25, 36, 49, 81, 100 and 121)
Red = prime numbers (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113 and 127)
Yellow = multiples of ten which are not square (10, 20, 30, 40, 50, 60, 70, 80, 90, 110 and 120)
Purple = multiples of 11 not included in any other category (22, 33, 44, 55, 66, 77, 88 and 99)
Gold = multiples of 17 greater than 60 (68, 85, 102 and 119)
Rose = multiples of 19 greater than 60 (76, 95 and 114)

Please refer to the above list of numbers for those which occur in more than one category.
Thanks again to Brianjn for all his help.

No Solution Yet Submitted by Josie Faulkner    
Rating: 4.5000 (4 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution (spoiler)--mostly comparison of computer languages | Comment 1 of 7

The program below first produces a verification of the grid of colors:

r r    g
 rypgryr
   yr
y  rpryg
rrr g p
 gbr r r
bpby  r
 rb gr r
 yb
  p  rp
r   r r
 r lyr
ggllr gy
 r ryrss
pyr r  s
l  r   p

And then a verification of the numbers assigned to each color:

1 8 27 64 125
4 9 16 25 36 49 81 100 121
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127
10 20 30 40 50 60 70 80 90 110 120
22 33 44 55 66 77 88 99
68 85 102 119
76 95 114

Then the solution to the puzzle:

  41  56  37  18  51  54  35  16
 
  38  19  40  55  36  17  50  53
 
  57  42  21  10  59  52  15  34
 
  20  39  58   7  22  13  60  49
 
  43   2  11  24   9   6  33  14
 
  28  25   8   3  12  23  48  61
 
   1  44  27  30  63  46   5  32
  
  26  29  64  45   4  31  62  47
 
  87  90 125 106  65  92 123 108
 
 126 105  88  91 124 107  66  93
 
  89  86  69 128  73  84 109 122
 
 104 127  72  85  70  67  94  75
 
  81 100 119  68  83  74 121 110
 
 118 103  82  71 120 113  76  95
 
  99  80 101 116  97  78 111 114
 
 102 117  98  79 112 115  96  77

Module Module1
    Dim a As ConsoleKeyInfo
    Dim num$, currx, curry, highLvl
    Dim g$(16, 8), b(16, 8)


    Sub Main()
        tStart = Microsoft.VisualBasic.DateAndTime.Timer
        Console.Clear()

        num$ = Space$(128)
        Mid$(num$, 1, 1) = "b"
        Mid$(num$, 8, 1) = "b"
        Mid$(num$, 27, 1) = "b"
        Mid$(num$, 64, 1) = "b"
        Mid$(num$, 125, 1) = "b"
        Mid$(num$, 4, 1) = "g"
        Mid$(num$, 9, 1) = "g"
        Mid$(num$, 16, 1) = "g"
        Mid$(num$, 25, 1) = "g"
        Mid$(num$, 36, 1) = "g"
        Mid$(num$, 49, 1) = "g"
        Mid$(num$, 81, 1) = "g"
        Mid$(num$, 100, 1) = "g"
        Mid$(num$, 121, 1) = "g"
        Mid$(num$, 2, 1) = "r"
        Mid$(num$, 3, 1) = "r"
        Mid$(num$, 5, 1) = "r"
        Mid$(num$, 7, 1) = "r"
        Mid$(num$, 11, 1) = "r"
        Mid$(num$, 13, 1) = "r"
        Mid$(num$, 17, 1) = "r"
        Mid$(num$, 19, 1) = "r"
        Mid$(num$, 23, 1) = "r"
        Mid$(num$, 29, 1) = "r"
        Mid$(num$, 31, 1) = "r"
        Mid$(num$, 37, 1) = "r"
        Mid$(num$, 41, 1) = "r"
        Mid$(num$, 43, 1) = "r"
        Mid$(num$, 47, 1) = "r"
        Mid$(num$, 53, 1) = "r"
        Mid$(num$, 59, 1) = "r"
        Mid$(num$, 61, 1) = "r"
        Mid$(num$, 67, 1) = "r"
        Mid$(num$, 71, 1) = "r"
        Mid$(num$, 73, 1) = "r"
        Mid$(num$, 79, 1) = "r"
        Mid$(num$, 83, 1) = "r"
        Mid$(num$, 89, 1) = "r"
        Mid$(num$, 97, 1) = "r"
        Mid$(num$, 101, 1) = "r"
        Mid$(num$, 103, 1) = "r"
        Mid$(num$, 107, 1) = "r"
        Mid$(num$, 109, 1) = "r"
        Mid$(num$, 113, 1) = "r"
        Mid$(num$, 127, 1) = "r"
        Mid$(num$, 10, 1) = "y"
        Mid$(num$, 20, 1) = "y"
        Mid$(num$, 30, 1) = "y"
        Mid$(num$, 40, 1) = "y"
        Mid$(num$, 50, 1) = "y"
        Mid$(num$, 60, 1) = "y"
        Mid$(num$, 70, 1) = "y"
        Mid$(num$, 80, 1) = "y"
        Mid$(num$, 90, 1) = "y"
        Mid$(num$, 110, 1) = "y"
        Mid$(num$, 120, 1) = "y"
        Mid$(num$, 22, 1) = "p"
        Mid$(num$, 33, 1) = "p"
        Mid$(num$, 44, 1) = "p"
        Mid$(num$, 55, 1) = "p"
        Mid$(num$, 66, 1) = "p"
        Mid$(num$, 77, 1) = "p"
        Mid$(num$, 88, 1) = "p"
        Mid$(num$, 99, 1) = "p"
        Mid$(num$, 68, 1) = "l"
        Mid$(num$, 85, 1) = "l"
        Mid$(num$, 102, 1) = "l"
        Mid$(num$, 119, 1) = "l"
        Mid$(num$, 76, 1) = "s"
        Mid$(num$, 95, 1) = "s"
        Mid$(num$, 114, 1) = "s"


        For r = 1 To 16 : For c = 1 To 8 : g$(r, c) = " " : Next : Next

        g$(1, 1) = "r"
        g$(1, 3) = "r"
        g$(2, 2) = "r"
        g$(2, 6) = "r"
        g$(2, 8) = "r"
        g$(3, 5) = "r"
        g$(4, 4) = "r"
        g$(4, 6) = "r"
        g$(5, 1) = "r"
        g$(5, 2) = "r"
        g$(5, 3) = "r"
        g$(6, 4) = "r"
        g$(6, 6) = "r"
        g$(6, 8) = "r"
        g$(7, 7) = "r"
        g$(8, 2) = "r"
        g$(8, 6) = "r"
        g$(8, 8) = "r"
        g$(10, 6) = "r"
        g$(11, 1) = "r"
        g$(11, 5) = "r"
        g$(11, 7) = "r"
        g$(12, 2) = "r"
        g$(12, 6) = "r"
        g$(13, 5) = "r"
        g$(14, 2) = "r"
        g$(14, 4) = "r"
        g$(14, 6) = "r"
        g$(15, 5) = "r"
        g$(15, 3) = "r"
        g$(16, 4) = "r"

        g$(1, 8) = "g"
        g$(2, 5) = "g"
        g$(4, 8) = "g"
        g$(5, 5) = "g"
        g$(6, 2) = "g"
        g$(8, 5) = "g"
        g$(13, 1) = "g"
        g$(13, 2) = "g"
        g$(13, 7) = "g"

        g$(6, 3) = "b"
        g$(7, 1) = "b"
        g$(7, 3) = "b"
        g$(8, 3) = "b"
        g$(9, 3) = "b"

        g$(2, 3) = "y"
        g$(2, 7) = "y"
        g$(3, 4) = "y"
        g$(4, 1) = "y"
        g$(4, 7) = "y"
        g$(7, 4) = "y"
        g$(9, 2) = "y"
        g$(12, 5) = "y"
        g$(13, 8) = "y"
        g$(14, 5) = "y"
        g$(15, 2) = "y"

        g$(2, 4) = "p"
        g$(4, 5) = "p"
        g$(5, 7) = "p"
        g$(7, 2) = "p"
        g$(10, 3) = "p"
        g$(10, 7) = "p"
        g$(15, 1) = "p"
        g$(16, 8) = "p"

        g$(12, 4) = "l"
        g$(13, 3) = "l"
        g$(13, 4) = "l"
        g$(16, 1) = "l"


        g$(14, 7) = "s"
        g$(14, 8) = "s"
        g$(15, 8) = "s"

        For row = 1 To 16
            For col = 1 To 8
                Console.Write(g$(row, col))
            Next
            Console.WriteLine("")
        Next

        b(5, 6) = 6
        b(11, 4) = 128

        curry = 5 : currx = 6

        For i = 1 To 128
            If Mid$(num$, i, 1) = "b" Then Console.Write(i) : Console.Write(" ")
        Next
        Console.WriteLine("")
        For i = 1 To 128
            If Mid$(num$, i, 1) = "g" Then Console.Write(i) : Console.Write(" ")
        Next
        Console.WriteLine("")
        For i = 1 To 128
            If Mid$(num$, i, 1) = "r" Then Console.Write(i) : Console.Write(" ")
        Next
        Console.WriteLine("")
        For i = 1 To 128
            If Mid$(num$, i, 1) = "y" Then Console.Write(i) : Console.Write(" ")
        Next
        Console.WriteLine("")
        For i = 1 To 128
            If Mid$(num$, i, 1) = "p" Then Console.Write(i) : Console.Write(" ")
        Next
        Console.WriteLine("")
        For i = 1 To 128
            If Mid$(num$, i, 1) = "l" Then Console.Write(i) : Console.Write(" ")
        Next
        Console.WriteLine("")
        For i = 1 To 128
            If Mid$(num$, i, 1) = "s" Then Console.Write(i) : Console.Write(" ")
        Next
        Console.WriteLine("")

        place(5)
        Console.WriteLine(Microsoft.VisualBasic.DateAndTime.Timer - tStart)

        Do
            a = Console.ReadKey(True)
        Loop While a.Key <> ConsoleKey.Escape

    End Sub
    Sub place(ByVal lvl)
        For dx = -2 To 2
            If dx <> 0 Then
                For dy = -(3 - Math.Abs(dx)) To 3 - Math.Abs(dx) Step 6 - 2 * Math.Abs(dx)
                    newx = currx + dx : newy = curry + dy
                    If newx > 0 And newx < 9 And newy > 0 And newy < 17 Then
                        If b(newy, newx) = 128 And lvl = 128 Then
                            For row = 1 To 16 : For col = 1 To 8
                                    Console.Write("{0,4}", b(row, col))
                                Next : Console.WriteLine("") : Next
                        ElseIf g$(newy, newx) = Mid$(num$, lvl, 1) And b(newy, newx) = 0 Then
                            savex = currx : savey = curry
                            currx = newx : curry = newy
                            b(curry, currx) = lvl

                            Select Case lvl
                                Case 1
                                    lv = 7 : currx = 6 : curry = 5
                                Case 2 To 5
                                    lv = lvl - 1
                                Case 7 To 127
                                    lv = lvl + 1
                            End Select

                            place(lv)


                            b(curry, currx) = 0
                            currx = savex : curry = savey
                        End If
                    End If
                Next
            End If
        Next
    End Sub
End Module

The above Visual Basic 2008 Express Edition program produced the results almost immediately, but took 12 seconds to complete, verifying that no other solution exists, rather than stopping once one solution was reached.

(Thanks, Penny, for telling us how to get VB 2008.)

It was a learning experience for me as the syntax of this version of Basic is almost completely different from VB 5.0, which was quite similar to QuickBasic, for DOS. One nice thing about it, though, is the formatting ("{0,4}") to line up columns of numbers.  In VB 5, that had to be handled by building strings (    
     printVal = Right("   " + Str(s0), 3)
     Print #2, printVal, cm$
     )
    
as in the following program for the same puzzle:

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   10605
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   14145
   LinkTopic       =   "Form1"
   ScaleHeight     =   10605
   ScaleWidth      =   14145
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Left            =   13080
      TabIndex        =   0
      Top             =   240
      Width           =   975
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim num$, currx, curry, highLvl
Dim g$(16, 8), b(16, 8)

Private Sub Command1_Click()
Cls
tStart = Timer

num$ = Space$(128)
Mid$(num$, 1, 1) = "b"
Mid$(num$, 8, 1) = "b"
Mid$(num$, 27, 1) = "b"
Mid$(num$, 64, 1) = "b"
Mid$(num$, 125, 1) = "b"
Mid$(num$, 4, 1) = "g"
Mid$(num$, 9, 1) = "g"
Mid$(num$, 16, 1) = "g"
Mid$(num$, 25, 1) = "g"
Mid$(num$, 36, 1) = "g"
Mid$(num$, 49, 1) = "g"
Mid$(num$, 81, 1) = "g"
Mid$(num$, 100, 1) = "g"
Mid$(num$, 121, 1) = "g"
Mid$(num$, 2, 1) = "r"
Mid$(num$, 3, 1) = "r"
Mid$(num$, 5, 1) = "r"
Mid$(num$, 7, 1) = "r"
Mid$(num$, 11, 1) = "r"
Mid$(num$, 13, 1) = "r"
Mid$(num$, 17, 1) = "r"
Mid$(num$, 19, 1) = "r"
Mid$(num$, 23, 1) = "r"
Mid$(num$, 29, 1) = "r"
Mid$(num$, 31, 1) = "r"
Mid$(num$, 37, 1) = "r"
Mid$(num$, 41, 1) = "r"
Mid$(num$, 43, 1) = "r"
Mid$(num$, 47, 1) = "r"
Mid$(num$, 53, 1) = "r"
Mid$(num$, 59, 1) = "r"
Mid$(num$, 61, 1) = "r"
Mid$(num$, 67, 1) = "r"
Mid$(num$, 71, 1) = "r"
Mid$(num$, 73, 1) = "r"
Mid$(num$, 79, 1) = "r"
Mid$(num$, 83, 1) = "r"
Mid$(num$, 89, 1) = "r"
Mid$(num$, 97, 1) = "r"
Mid$(num$, 101, 1) = "r"
Mid$(num$, 103, 1) = "r"
Mid$(num$, 107, 1) = "r"
Mid$(num$, 109, 1) = "r"
Mid$(num$, 113, 1) = "r"
Mid$(num$, 127, 1) = "r"
Mid$(num$, 10, 1) = "y"
Mid$(num$, 20, 1) = "y"
Mid$(num$, 30, 1) = "y"
Mid$(num$, 40, 1) = "y"
Mid$(num$, 50, 1) = "y"
Mid$(num$, 60, 1) = "y"
Mid$(num$, 70, 1) = "y"
Mid$(num$, 80, 1) = "y"
Mid$(num$, 90, 1) = "y"
Mid$(num$, 110, 1) = "y"
Mid$(num$, 120, 1) = "y"
Mid$(num$, 22, 1) = "p"
Mid$(num$, 33, 1) = "p"
Mid$(num$, 44, 1) = "p"
Mid$(num$, 55, 1) = "p"
Mid$(num$, 66, 1) = "p"
Mid$(num$, 77, 1) = "p"
Mid$(num$, 88, 1) = "p"
Mid$(num$, 99, 1) = "p"
Mid$(num$, 68, 1) = "l"
Mid$(num$, 85, 1) = "l"
Mid$(num$, 102, 1) = "l"
Mid$(num$, 119, 1) = "l"
Mid$(num$, 76, 1) = "s"
Mid$(num$, 95, 1) = "s"
Mid$(num$, 114, 1) = "s"


For r = 1 To 16: For c = 1 To 8: g$(r, c) = " ": Next: Next

g$(1, 1) = "r"
g$(1, 3) = "r"
g$(2, 2) = "r"
g$(2, 6) = "r"
g$(2, 8) = "r"
g$(3, 5) = "r"
g$(4, 4) = "r"
g$(4, 6) = "r"
g$(5, 1) = "r"
g$(5, 2) = "r"
g$(5, 3) = "r"
g$(6, 4) = "r"
g$(6, 6) = "r"
g$(6, 8) = "r"
g$(7, 7) = "r"
g$(8, 2) = "r"
g$(8, 6) = "r"
g$(8, 8) = "r"
g$(10, 6) = "r"
g$(11, 1) = "r"
g$(11, 5) = "r"
g$(11, 7) = "r"
g$(12, 2) = "r"
g$(12, 6) = "r"
g$(13, 5) = "r"
g$(14, 2) = "r"
g$(14, 4) = "r"
g$(14, 6) = "r"
g$(15, 5) = "r"
g$(15, 3) = "r"
g$(16, 4) = "r"

g$(1, 8) = "g"
g$(2, 5) = "g"
g$(4, 8) = "g"
g$(5, 5) = "g"
g$(6, 2) = "g"
g$(8, 5) = "g"
g$(13, 1) = "g"
g$(13, 2) = "g"
g$(13, 7) = "g"

g$(6, 3) = "b"
g$(7, 1) = "b"
g$(7, 3) = "b"
g$(8, 3) = "b"
g$(9, 3) = "b"

g$(2, 3) = "y"
g$(2, 7) = "y"
g$(3, 4) = "y"
g$(4, 1) = "y"
g$(4, 7) = "y"
g$(7, 4) = "y"
g$(9, 2) = "y"
g$(12, 5) = "y"
g$(13, 8) = "y"
g$(14, 5) = "y"
g$(15, 2) = "y"

g$(2, 4) = "p"
g$(4, 5) = "p"
g$(5, 7) = "p"
g$(7, 2) = "p"
g$(10, 3) = "p"
g$(10, 7) = "p"
g$(15, 1) = "p"
g$(16, 8) = "p"

g$(12, 4) = "l"
g$(13, 3) = "l"
g$(13, 4) = "l"
g$(16, 1) = "l"


g$(14, 7) = "s"
g$(14, 8) = "s"
g$(15, 8) = "s"

FontName = "courier new"

For row = 1 To 16
 For col = 1 To 8
  Print g$(row, col);
 Next
 Print
Next
    
b(5, 6) = 6
b(11, 4) = 128

curry = 5: currx = 6

For i = 1 To 128
 If Mid$(num$, i, 1) = "b" Then Print i;
Next
Print
For i = 1 To 128
 If Mid$(num$, i, 1) = "g" Then Print i;
Next
Print
For i = 1 To 128
 If Mid$(num$, i, 1) = "r" Then Print i;
Next
Print
For i = 1 To 128
 If Mid$(num$, i, 1) = "y" Then Print i;
Next
Print
For i = 1 To 128
 If Mid$(num$, i, 1) = "p" Then Print i;
Next
Print
For i = 1 To 128
 If Mid$(num$, i, 1) = "l" Then Print i;
Next
Print
For i = 1 To 128
 If Mid$(num$, i, 1) = "s" Then Print i;
Next
Print
place 5

Print Timer - tStart
End Sub

Sub place(lvl)
 DoEvents
 For dx = -2 To 2
   If dx <> 0 Then
    For dy = -(3 - Abs(dx)) To 3 - Abs(dx) Step 6 - 2 * Abs(dx)
     newx = currx + dx: newy = curry + dy
     If newx > 0 And newx < 9 And newy > 0 And newy < 17 Then
      If b(newy, newx) = 128 And lvl = 128 Then
        For row = 1 To 16: For col = 1 To 8
          pr$ = Right$("    " + Str$(b(row, col)), 4)
          Print pr$;
        Next: Print: Next
      ElseIf g$(newy, newx) = Mid$(num$, lvl, 1) And b(newy, newx) = 0 Then
        savex = currx: savey = curry
        currx = newx: curry = newy
        b(curry, currx) = lvl

        Select Case lvl
          Case 1
           lv = 7: currx = 6: curry = 5
          Case 2 To 5
           lv = lvl - 1
          Case 7 To 127
           lv = lvl + 1
        End Select

        place lv


        b(curry, currx) = 0
        currx = savex: curry = savey
      End If
     End If
    Next
   End If
 Next
End Sub


which completed in 15 seconds.

So there was a slight speed improvement in VB 2008 compared to VB 5. Also the newer Basic allows console output rather than requiring the building of a file for output, or as in this program, on the form itself, from which the text can't be copied.

The QB program had both good formatting capability (USING "####"), and output to the console (Command Prompt), but the speed was slow, taking 35 seconds on the same computer as the VB 5 and VB 2008 versions.  On my older computer, it took 93 seconds as it had only a 2 GHz processor rather than a 4 GHz Intel Core 2 Duo processor.

DECLARE SUB place (lvl!)
CLEAR , , 30000

DIM SHARED num$, currx, curry, highLvl
CLS
tStart = TIMER

num$ = SPACE$(128)
MID$(num$, 1, 1) = "b"
MID$(num$, 8, 1) = "b"
MID$(num$, 27, 1) = "b"
MID$(num$, 64, 1) = "b"
MID$(num$, 125, 1) = "b"
MID$(num$, 4, 1) = "g"
MID$(num$, 9, 1) = "g"
MID$(num$, 16, 1) = "g"
MID$(num$, 25, 1) = "g"
MID$(num$, 36, 1) = "g"
MID$(num$, 49, 1) = "g"
MID$(num$, 81, 1) = "g"
MID$(num$, 100, 1) = "g"
MID$(num$, 121, 1) = "g"
MID$(num$, 2, 1) = "r"
MID$(num$, 3, 1) = "r"
MID$(num$, 5, 1) = "r"
MID$(num$, 7, 1) = "r"
MID$(num$, 11, 1) = "r"
MID$(num$, 13, 1) = "r"
MID$(num$, 17, 1) = "r"
MID$(num$, 19, 1) = "r"
MID$(num$, 23, 1) = "r"
MID$(num$, 29, 1) = "r"
MID$(num$, 31, 1) = "r"
MID$(num$, 37, 1) = "r"
MID$(num$, 41, 1) = "r"
MID$(num$, 43, 1) = "r"
MID$(num$, 47, 1) = "r"
MID$(num$, 53, 1) = "r"
MID$(num$, 59, 1) = "r"
MID$(num$, 61, 1) = "r"
MID$(num$, 67, 1) = "r"
MID$(num$, 71, 1) = "r"
MID$(num$, 73, 1) = "r"
MID$(num$, 79, 1) = "r"
MID$(num$, 83, 1) = "r"
MID$(num$, 89, 1) = "r"
MID$(num$, 97, 1) = "r"
MID$(num$, 101, 1) = "r"
MID$(num$, 103, 1) = "r"
MID$(num$, 107, 1) = "r"
MID$(num$, 109, 1) = "r"
MID$(num$, 113, 1) = "r"
MID$(num$, 127, 1) = "r"
MID$(num$, 10, 1) = "y"
MID$(num$, 20, 1) = "y"
MID$(num$, 30, 1) = "y"
MID$(num$, 40, 1) = "y"
MID$(num$, 50, 1) = "y"
MID$(num$, 60, 1) = "y"
MID$(num$, 70, 1) = "y"
MID$(num$, 80, 1) = "y"
MID$(num$, 90, 1) = "y"
MID$(num$, 110, 1) = "y"
MID$(num$, 120, 1) = "y"
MID$(num$, 22, 1) = "p"
MID$(num$, 33, 1) = "p"
MID$(num$, 44, 1) = "p"
MID$(num$, 55, 1) = "p"
MID$(num$, 66, 1) = "p"
MID$(num$, 77, 1) = "p"
MID$(num$, 88, 1) = "p"
MID$(num$, 99, 1) = "p"
MID$(num$, 68, 1) = "l"
MID$(num$, 85, 1) = "l"
MID$(num$, 102, 1) = "l"
MID$(num$, 119, 1) = "l"
MID$(num$, 76, 1) = "s"
MID$(num$, 95, 1) = "s"
MID$(num$, 114, 1) = "s"

DIM SHARED g$(16, 8), b(16, 8)

FOR r = 1 TO 16: FOR c = 1 TO 8: g$(r, c) = " ": NEXT: NEXT

g$(1, 1) = "r"
g$(1, 3) = "r"
g$(2, 2) = "r"
g$(2, 6) = "r"
g$(2, 8) = "r"
g$(3, 5) = "r"
g$(4, 4) = "r"
g$(4, 6) = "r"
g$(5, 1) = "r"
g$(5, 2) = "r"
g$(5, 3) = "r"
g$(6, 4) = "r"
g$(6, 6) = "r"
g$(6, 8) = "r"
g$(7, 7) = "r"
g$(8, 2) = "r"
g$(8, 6) = "r"
g$(8, 8) = "r"
g$(10, 6) = "r"
g$(11, 1) = "r"
g$(11, 5) = "r"
g$(11, 7) = "r"
g$(12, 2) = "r"
g$(12, 6) = "r"
g$(13, 5) = "r"
g$(14, 2) = "r"
g$(14, 4) = "r"
g$(14, 6) = "r"
g$(15, 5) = "r"
g$(15, 3) = "r"
g$(16, 4) = "r"

g$(1, 8) = "g"
g$(2, 5) = "g"
g$(4, 8) = "g"
g$(5, 5) = "g"
g$(6, 2) = "g"
g$(8, 5) = "g"
g$(13, 1) = "g"
g$(13, 2) = "g"
g$(13, 7) = "g"

g$(6, 3) = "b"
g$(7, 1) = "b"
g$(7, 3) = "b"
g$(8, 3) = "b"
g$(9, 3) = "b"

g$(2, 3) = "y"
g$(2, 7) = "y"
g$(3, 4) = "y"
g$(4, 1) = "y"
g$(4, 7) = "y"
g$(7, 4) = "y"
g$(9, 2) = "y"
g$(12, 5) = "y"
g$(13, 8) = "y"
g$(14, 5) = "y"
g$(15, 2) = "y"

g$(2, 4) = "p"
g$(4, 5) = "p"
g$(5, 7) = "p"
g$(7, 2) = "p"
g$(10, 3) = "p"
g$(10, 7) = "p"
g$(15, 1) = "p"
g$(16, 8) = "p"

g$(12, 4) = "l"
g$(13, 3) = "l"
g$(13, 4) = "l"
g$(16, 1) = "l"


g$(14, 7) = "s"
g$(14, 8) = "s"
g$(15, 8) = "s"

FOR row = 1 TO 16
 FOR col = 1 TO 8
  PRINT g$(row, col);
 NEXT
 PRINT
NEXT
    
b(5, 6) = 6
b(11, 4) = 128

curry = 5: currx = 6

FOR i = 1 TO 128
 IF MID$(num$, i, 1) = "b" THEN PRINT i;
NEXT
PRINT
FOR i = 1 TO 128
 IF MID$(num$, i, 1) = "g" THEN PRINT i;
NEXT
PRINT
FOR i = 1 TO 128
 IF MID$(num$, i, 1) = "r" THEN PRINT i;
NEXT
PRINT
FOR i = 1 TO 128
 IF MID$(num$, i, 1) = "y" THEN PRINT i;
NEXT
PRINT
FOR i = 1 TO 128
 IF MID$(num$, i, 1) = "p" THEN PRINT i;
NEXT
PRINT
FOR i = 1 TO 128
 IF MID$(num$, i, 1) = "l" THEN PRINT i;
NEXT
PRINT
FOR i = 1 TO 128
 IF MID$(num$, i, 1) = "s" THEN PRINT i;
NEXT
PRINT
place 5

PRINT TIMER - tStart

SUB place (lvl)
 FOR dx = -2 TO 2
   IF dx <> 0 THEN
    FOR dy = -(3 - ABS(dx)) TO 3 - ABS(dx) STEP 6 - 2 * ABS(dx)
     newx = currx + dx: newy = curry + dy
     IF newx > 0 AND newx < 9 AND newy > 0 AND newy < 17 THEN
      IF b(newy, newx) = 128 AND lvl = 128 THEN
        FOR row = 1 TO 16: FOR col = 1 TO 8
          PRINT USING "####"; b(row, col);
        NEXT: PRINT : NEXT
      ELSEIF g$(newy, newx) = MID$(num$, lvl, 1) AND b(newy, newx) = 0 THEN
        savex = currx: savey = curry
        currx = newx: curry = newy
        b(curry, currx) = lvl

        SELECT CASE lvl
          CASE 1
           lv = 7: currx = 6: curry = 5
          CASE 2 TO 5
           lv = lvl - 1
          CASE 7 TO 127
           lv = lvl + 1
        END SELECT

        place lv

        b(curry, currx) = 0
        currx = savex: curry = savey
      END IF
     END IF
    NEXT
   END IF
 NEXT
END SUB

 


  Posted by Charlie on 2008-07-11 10:43:12
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information