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

Home > Games
Jump, Skip and Hop (Posted on 2010-11-03) Difficulty: 3 of 5
What's the shortest path from A to R in the array below, if your moves are to be in the repeated length sequence 3, 2, 1, 3, 2, 1... (such as, say ADJMC...), and no two successive moves are in the same direction or in the reverse direction? Moves may be orthogonal or diagonal. No move may end on a hyphen (-) but may jump over them and the R must be reached on exact count.
ABCD-
EFGH-
--IJK
-LM-N
OP-QR

  Submitted by Charlie    
No Rating
Solution: (Hide)
Nine steps:
ADJNLHCMNR

Taken from the output of:

DECLARE SUB addon ()
CLEAR , , 25000
CLS

DATA abcd-,efgh-,--ijk,-lm-n,op-qr
DIM SHARED g$(5, 5)

FOR r = 1 TO 5
  READ row$
  FOR c = 1 TO 5
    g$(r, c) = MID$(row$, c, 1)
  NEXT
NEXT

DIM SHARED mvs$, currR, currC, prevDR, prevDC

currR = 1: currC = 1: mvs$ = "a"

addon

SUB addon

sz = 3 - ((LEN(mvs$) - 1) MOD 3)

FOR dr = -1 TO 1
FOR dc = -1 TO 1

  IF dr <> 0 OR dc <> 0 THEN
    IF (dr <> prevDR OR dc <> prevDC) AND (dr <> -prevDR OR dc <> -prevDC) THEN
      newR = currR + dr * sz: newC = currC + dc * sz
      IF newR >= 1 AND newR <= 5 AND newC >= 1 AND newC <= 5 THEN
        IF g$(newR, newC) <> "-" THEN
          saveR = currR: saveC = currC
          currR = newR: currC = newC
          saveDR = prevDR: saveDC = prevDC
          prevDR = dr: prevDC = dc
          mvs$ = mvs$ + g$(currR, currC)
          IF g$(currR, currC) = "r" THEN
            PRINT mvs$
          ELSE
           IF LEN(mvs$) < 12 THEN
            addon
           END IF
          END IF
          mvs$ = LEFT$(mvs$, LEN(mvs$) - 1)
          prevDR = saveDR: prevDC = saveDC
          currR = saveR: currC = saveC
        END IF
      END IF
    END IF
  END IF
NEXT dc
NEXT dr

END SUB

adjmcaehlpr
adjnlfcmefr
adjnlfcmnr
adjnlhcmefr
adjnlhcmnr

Comments: ( You must be logged in to post comments.)
  Subject Author Date
re(2): Some ThoughtsSteve Herman2010-11-03 22:43:54
re: Some Thoughtsed bottemiller2010-11-03 21:13:19
Some ThoughtsSome ThoughtsSteve Herman2010-11-03 20:54:41
re(2): Hoping or Hopping Hopefullyed bottemiller2010-11-03 17:16:30
re: Hoping or Hopping HopefullyCharlie2010-11-03 16:33:17
Hoping or Hopping Hopefullyed bottemiller2010-11-03 13:08:11
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