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

Home > Numbers
Sadism (Posted on 2012-12-24) Difficulty: 3 of 5

No Solution Yet Submitted by brianjn    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer-assisted solution | Comment 3 of 9 |

Assuming that "lateral" means parallel to one of the sides of the square, the following program changes the grid into a conventional maze:

DECLARE FUNCTION gcd! (x!, y!)
DATA    40,70,119,25,56,50,100
DATA    35,33,51,65,39,65,38
DATA    28,121,253,143,49,14,56
DATA    77,52,65,30,35,10,133
DATA    14,78,77,14,20,21,45
DATA    15,30,55,65,42,14,15
DATA    85,68,51,66,55,45,72

FOR r = 1 TO 7
FOR c = 1 TO 7
  READ grid(r, c)
NEXT
NEXT

CLS

PRINT "+-----+-----+-----+-----+-----+-----+-----+"
FOR r = 1 TO 7
   PRINT "|     ";
   FOR c = 1 TO 6
     IF gcd(grid(r, c), grid(r, c + 1)) = 1 THEN PRINT "|     "; :  ELSE PRINT "      ";
   NEXT c
   PRINT "|"
   PRINT "|";
   FOR c = 1 TO 6
     PRINT USING " ### "; grid(r, c);
     IF gcd(grid(r, c), grid(r, c + 1)) = 1 THEN PRINT "|"; :  ELSE PRINT " ";
   NEXT c
   PRINT USING " ### "; grid(r, 7);
   PRINT "|"
   PRINT "|     ";
   FOR c = 1 TO 6
     IF gcd(grid(r, c), grid(r, c + 1)) = 1 THEN PRINT "|     "; :  ELSE PRINT "      ";
   NEXT c
   PRINT "|"
   IF r <> 7 THEN
     FOR c = 1 TO 7
       PRINT "+";
       IF gcd(grid(r, c), grid(r + 1, c)) = 1 THEN PRINT "-----"; :  ELSE PRINT "     ";
     NEXT c
     PRINT "+"
   END IF
NEXT r
PRINT "+-----+-----+-----+-----+-----+-----+-----+"

FUNCTION gcd (x, y)
 dnd = x: dvr = y
 IF dnd < dvr THEN SWAP dnd, dvr
 DO
   q = INT(dnd / dvr)
   r = dnd - q * dvr
   dnd = dvr: dvr = r
 LOOP UNTIL r = 0
 gcd = dnd
END FUNCTION

The result is:

+-----+-----+-----+-----+-----+-----+-----+
|                 |     |                 |
|  40    70   119 |  25 |  56    50   100 |
|                 |     |                 |
+     +-----+     +     +-----+     +     +
|     |           |                 |     |
|  35 |  33    51 |  65    39    65 |  38 |
|     |           |                 |     |
+     +     +-----+     +-----+-----+     +
|     |                 |                 |
|  28 | 121   253   143 |  49    14    56 |
|     |                 |                 |
+     +-----+-----+-----+     +     +     +
|     |                             |     |
|  77 |  52    65    30    35    10 | 133 |
|     |                             |     |
+     +     +-----+     +     +-----+-----+
|           |                 |           |
|  14    78 |  77    14    20 |  21    45 |
|           |                 |           |
+-----+     +     +-----+     +     +     +
|                       |           |     |
|  15    30    55    65 |  42    14 |  15 |
|                       |           |     |
+     +     +-----+-----+-----+-----+     +
|                                         |
|  85    68    51    66    55    45    72 |
|                                         |
+-----+-----+-----+-----+-----+-----+-----+

The shortest path seems to follow the numbers 25, 65, 143, 253, 121, 33, 51, 119, 70, 40, 35, 28, 77, 14, 78, 30, 68, 51 and 60, a total of 19 squares or 18 moves.

The longest without going into any square more than once seems to be 25, 65, 39, 65, 50, 100, 38, 56, 14, 10 (or 49), 35, 30, 65, 52, 78, 30, 55, 77, 14, 20, 42, 14, 21, 45, 15, 72, 45, 55 and 66, a total of 29 squares (28 moves).


  Posted by Charlie on 2012-12-24 17:54:59
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 (16)
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