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

Home > Logic
Pushing numbers (Posted on 2007-02-12) Difficulty: 3 of 5
You need to make it so that all the numbers from 1 to 6 appear once in every row and column. You can only do that by "pushing" the rows down and the columns left. Each time you "push" a row or a column all the numbers in it move 1 block to the direction you have pushed it.

1

3

6

2

5

4

6

4

1

5

1

3

2

5

2

6

3

5

2

6

1

4

4

4

6

3

4

3

2

1

5

2

6

5

1

3

Can you complete the grid?

See The Solution Submitted by Assaf    
Rating: 4.2857 (7 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 1 of 4
The five offset rows and five offset columns each have to be done once, in some order, so some permutation of these has to work. I numbered the offset columns 1 - 5, meaning that the one I numbered 1 was really the second column (the first column, having the 3 at the bottom, I counted as zero). The rows, from top to bottom are a - e (row f would never be involved in a push to the left).

The order is a4e3c1d5b2, which is interpreted as
push row a left
push offset column 4 (overall column 5) down

etc.

The positions after each move are:

   1 3 6 2 5  
 4 6 4 1 5 1  
   3 2 5 2 6 3
   5 2 6 1 4 4
   4 6 3 4 3 2
   1 5 2 6 5 1
 3            

   1 3 6   5 
 4 6 4 1 2 1  
   3 2 5 5 6 3
   5 2 6 2 4 4
   4 6 3 1 3 2
   1 5 2 4 5 1
 3       6    

   1 3 6   5 
 4 6 4 1 2 1  
   3 2 5 5 6 3
   5 2 6 2 4 4
   4 6 3 1 3 2
 1 5 2 4 5 1  
 3       6    

   1 3     5 
 4 6 4 6 2 1  
   3 2 1 5 6 3
   5 2 5 2 4 4
   4 6 6 1 3 2
 1 5 2 3 5 1  
 3     4 6    

   1 3     5 
 4 6 4 6 2 1  
   3 2 1 5 6 3
 5 2 5 2 4 4  
   4 6 6 1 3 2
 1 5 2 3 5 1  
 3     4 6    

     3     5 
 4 1 4 6 2 1  
   6 2 1 5 6 3
 5 3 5 2 4 4  
   2 6 6 1 3 2
 1 4 2 3 5 1  
 3 5   4 6    

     3     5 
 4 1 4 6 2 1  
   6 2 1 5 6 3
 5 3 5 2 4 4  
 2 6 6 1 3 2  
 1 4 2 3 5 1  
 3 5   4 6    

     3       
 4 1 4 6 2 5  
   6 2 1 5 1 3
 5 3 5 2 4 6  
 2 6 6 1 3 4  
 1 4 2 3 5 2  
 3 5   4 6 1  

     3       
 4 1 4 6 2 5  
 6 2 1 5 1 3  
 5 3 5 2 4 6  
 2 6 6 1 3 4  
 1 4 2 3 5 2  
 3 5   4 6 1  

             
 4 1 3 6 2 5  
 6 2 4 5 1 3  
 5 3 1 2 4 6  
 2 6 5 1 3 4  
 1 4 6 3 5 2  
 3 5 2 4 6 1  

The program:

DECLARE SUB permute (a$)
DATA 0,1,3,6,2,5,0
DATA 0,4,6,4,1,5,1
DATA 0,3,2,5,2,6,3
DATA 0,5,2,6,1,4,4
DATA 0,4,6,3,4,3,2
DATA 0,1,5,2,6,5,1
DATA 3,0,0,0,0,0,0

s$ = "12345abcde"
sh$ = s$

OPEN "pushnumb.txt" FOR OUTPUT AS #2

DO
  RESTORE
  FOR r = 0 TO 6
   FOR c = 1 TO 7
    READ g(r, c)
   NEXT
  NEXT

  FOR spos = 1 TO 10
    m$ = MID$(s$, spos, 1)
    IF INSTR("12345", m$) THEN
      c = 1 + VAL(m$)
      FOR r = 6 TO 1 STEP -1
       g(r, c) = g(r - 1, c)
      NEXT
    ELSE
      r = INSTR("abcde", m$)
      FOR c = 1 TO 6
       g(r, c) = g(r, c + 1)
      NEXT
    END IF
  NEXT
  good = 1
  FOR r = 1 TO 6
   REDIM check(6)
   FOR c = 1 TO 6
    v = g(r, c)
    IF check(v) THEN good = 0: EXIT FOR
    check(v) = 1
   NEXT
   IF good = 0 THEN EXIT FOR
  NEXT
  IF good THEN
    FOR c = 1 TO 6
     REDIM check(6)
     FOR r = 1 TO 6
      v = g(r, c)
      IF check(v) THEN good = 0: EXIT FOR
      check(v) = 1
     NEXT
     IF good = 0 THEN EXIT FOR
    NEXT
  END IF
  IF good THEN
    PRINT s$
    PRINT #2, s$
    RESTORE
    FOR r = 0 TO 6
     FOR c = 1 TO 7
      READ g(r, c)
     NEXT
    NEXT

    FOR spos = 1 TO 10
      m$ = MID$(s$, spos, 1)
      IF INSTR("12345", m$) THEN
        c = 1 + VAL(m$)
        FOR r = 6 TO 1 STEP -1
         g(r, c) = g(r - 1, c)
        NEXT
        g(0, c) = 0
      ELSE
        r = INSTR("abcde", m$)
        FOR c = 1 TO 6
         g(r, c) = g(r, c + 1)
        NEXT
        g(r, 7) = 0
      END IF
      FOR r = 0 TO 6
       FOR c = 1 TO 7
         IF g(r, c) = 0 THEN
          PRINT #2, "  ";
         ELSE
          PRINT #2, USING "##"; g(r, c);
         END IF
       NEXT
       PRINT #2,
      NEXT
      PRINT #2,
    NEXT
  END IF

  permute s$
LOOP UNTIL s$ = sh$

CLOSE

The permute subroutine is elsewhere on the site.

The program examined more sequences than strictly necessary. What was necessary was to consider even those possibilities that 2 or more columns or 2 or more rows might appear in succession. In those cases it would not matter which of the rows (or which of the columns) was done in which order within the grouping.  But I didn't find an easy algorithm for eliminating the redundant checks and so did all permutations of the 10 possible moves.

  Posted by Charlie on 2007-02-12 11:01:51
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 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information