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

Home > Algorithms
Unbounded Maze (Posted on 2008-01-18) Difficulty: 3 of 5
A programmable robotic mouse is placed at an intersection on a square grid, the borders of which are extendable as needed.

From its initial location the mouse moves one cell forward. It turns right with its next move incrementing by 1.

This incremental process continues up to a certain constraint whereby the mouse resumes the process with a move of one space until that constraint is met again; continue this process until you either return to your starting position or you evidently will never return.

What generalisations can be made about how variations of the value of the constraint affect the path forced upon the mouse?

M

Note:It will be necessary to test a range of constraining values.

See The Solution Submitted by brianjn    
Rating: 4.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re(5): No Subject - Constraint | Comment 13 of 19 |
(In reply to re(4): No Subject - Constraint by nikki)

The following program follows nikki's 2nd program (the Fibonacci one):

CLS
c = 0
fprev = 0
fcurr = 1
temp = 0
x = 0: y = 0
dx = 0: dy = 1
PRINT x; y
' x is positive to the right
' y contrary to convention is positive to the bottom
'   but this doesn't matter as left turns would work just as good
'   as right turns.
DO
 s = 0
 c = fcurr
 DO
  s = s + 1
  PRINT TAB(8); s; c
  x = x + dx * s: y = y + dy * s
  PRINT x; y
  IF x = 0 AND y = 0 THEN END
  dyNew = dx: dxNew = -dy
  dy = dyNew: dx = dxNew
 LOOP UNTIL s = c
 temp = fcurr
 fcurr = fprev + fcurr
 fprev = temp
LOOP UNTIL x = 0 AND y = 0

Note however the bolded line above, which checks for a return to the origin within the inner loop, rather than the outer. It finds that indeed the mouse does land exactly on the starting point at step 9. The following was the output:

 x  y   s  c 
 0  0
        1  1
 0  1
        1  1
-1  1
        1  2
-1  0
        2  2
 1  0
        1  3
 1  1
        2  3
-1  1
        3  3
-1 -2
        1  5
 0 -2
        2  5
 0  0

Indeed, it's confirmed that on step 4 the mouse passes through the origin, from (-1,0) to (1,0).

A picture (till the mouse leaves the viewing area):

                               J                   K
                                 F               G
                      v           wB           C
                        r       s    x       y
                         P                  Q
                          n   o        t   u
                           L              M
       p            j       k            q
                          m lH         sIr
         l            f   g            m
                        q     pD     wE    v
           h       b    c            i
                      u d       tz AA        z
             d       78            e
                    i     h      Ex            D
               9   a 394         a
                     615       I    B            H
                 5             6
                             M        F            L
                   1         2
                           K            J
                     X     Y
                         O                N
                       T U
                       S                    R
                     W   V
                   0       Z
                 4           3
               8               7
             c                   b
           g                       f
         k                           j
       o                               n

from

CLS
x = 20: y = 36
dirx = 0: diry = 1
amt = 1
lim = 1

s$ = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
mNo = 1
fprev = 0
fcurr = 1
lim = fcurr
DO
 moveNo = moveNo + 1
 LOCATE y - 16, x + 25: PRINT MID$(s$, mNo, 1);
 DO: a$ = INKEY$: LOOP UNTIL a$ > "": IF a$ = CHR$(27) THEN EXIT DO
 x = x + dirx * amt: y = y + diry * amt
 IF x = 20 AND y = 36 THEN
   ct = ct + 1: LOCATE 47, ct * 6: PRINT moveNo;
 END IF
 amt = amt + 1
 IF amt > lim THEN
   amt = 1
   h = fcurr
   fcurr = fcurr + fprev
   fprev = h
   lim = fcurr
   REM
 END IF
 diryNew = dirx: dirxNew = -diry
 diry = diryNew: dirx = dirxNew
 mNo = mNo + 1
 IF mNo > LEN(s$) THEN mNo = 1
LOOP

and the mouse visits start only on step 9 before leaving.


  Posted by Charlie on 2008-01-23 11:28:25
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 (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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