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

Home > General
Nine square pieces (Posted on 2005-12-11) Difficulty: 2 of 5
You are given 9 square pieces (A - I), each one having in each side a number from 1 to 4, positive or negative, as shown:
        +------------+   +------------+   +------------+
        |     +1     |   |     +2     |   |     +1     |
        |            |   |            |   |            |
        |-3   (A)  +4|   |+3   (B)  -1|   |+3   (C)  -2|
        |            |   |            |   |            |
        |     -2     |   |     -4     |   |     -4     |
        +------------+   +------------+   +------------+
        +------------+   +------------+   +------------+
        |     -1     |   |     -2     |   |     +2     |
        |            |   |            |   |            |
        |+2   (D)  -4|   |-4   (E)  +1|   |+1   (F)  -3|
        |            |   |            |   |            |
        |     +1     |   |     +3     |   |     -4     |
        +------------+   +------------+   +------------+
        +------------+   +------------+   +------------+
        |     +3     |   |     -3     |   |     +3     |
        |            |   |            |   |            |
        |-2   (G)  +4|   |+2   (H)  -4|   |-2   (I)  +4|
        |            |   |            |   |            |
        |     -1     |   |     +1     |   |     -3     |
        +------------+   +------------+   +------------+
Your task is to juxtapose them forming a 3x3 grid so that "touching numbers" of each pair of touching pieces (horizontally or vertically) adds to zero.

Note: You are free to rotate the pieces.

See The Solution Submitted by pcbouhid    
Rating: 3.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Both (all) solutions -- computer used -- spoiler | Comment 5 of 9 |

The following program finds 4 solutions, but they consist of two significant solutions plus the trivial swapping of pieces F and H, which are identical except for their presented rotation.  One significant solution has A in the center, and the other has G.  The center piece is always assumed to be in the same orientation as originally presented in the puzzle; any rotation of it would just produce trivial rotations of the whole solutions.

DATA 1,4,-2,-3,  2,-1,-4,3, 1,-2,-4,3
DATA -1,-4,1,2, -2,1,3,-4, 2,-3,-4,1
DATA 3,4,-1,-2, -3,-4,1,2, 3,4,-3,-2

DIM SHARED pc(9, 4), used(9), board(9, 9)

CLS

FOR i = 1 TO 9
 FOR j = 1 TO 4
  READ pc(i, j)
 NEXT
NEXT

FOR ctr = 1 TO 9
 used(ctr) = 1
 board(4, 5) = pc(ctr, 1)
 board(5, 6) = pc(ctr, 2)
 board(6, 5) = pc(ctr, 3)
 board(5, 4) = pc(ctr, 4)
 board(5, 5) = ctr

FOR t = 1 TO 9
 IF used(t) = 0 THEN
  used(t) = 1
  good = 0
  FOR i = 1 TO 4
   IF pc(t, i) = -board(4, 5) THEN
     good = 1: EXIT FOR
   END IF
  NEXT i
  IF good THEN
    board(3, 5) = pc(t, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(2, 4) = pc(t, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(1, 5) = pc(t, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(2, 6) = pc(t, i)
    board(2, 5) = t

FOR tr = 1 TO 9
 IF used(tr) = 0 THEN
  used(tr) = 1
  good = 0
  FOR i = 1 TO 4
   IF pc(tr, i) = -board(2, 6) THEN
     good = 1: EXIT FOR
   END IF
  NEXT i
  IF good THEN
    board(2, 7) = pc(tr, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(1, 8) = pc(tr, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(2, 9) = pc(tr, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(3, 8) = pc(tr, i)
    board(2, 8) = tr

FOR r = 1 TO 9
 IF used(r) = 0 THEN
  used(r) = 1
  good = 0
  FOR i = 1 TO 4
   IF pc(r, i) = -board(3, 8) THEN
     good = 1: EXIT FOR
   END IF
  NEXT i
  IF good THEN
    board(4, 8) = pc(r, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(5, 9) = pc(r, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(6, 8) = pc(r, i): i = i + 1: IF i > 4 THEN i = i - 4
    IF pc(r, i) <> -board(5, 6) THEN good = 0
    board(5, 7) = pc(r, i)
    board(5, 8) = r
    IF good THEN

FOR br = 1 TO 9
 IF used(br) = 0 THEN
  used(br) = 1
  good = 0
  FOR i = 1 TO 4
   IF pc(br, i) = -board(6, 8) THEN
     good = 1: EXIT FOR
   END IF
  NEXT i
  IF good THEN
    board(7, 8) = pc(br, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(8, 9) = pc(br, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(9, 8) = pc(br, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(8, 7) = pc(br, i)
    board(8, 8) = br
    IF good THEN

FOR b = 1 TO 9
 IF used(b) = 0 THEN
  used(b) = 1
  good = 0
  FOR i = 1 TO 4
   IF pc(b, i) = -board(8, 7) THEN
     good = 1: EXIT FOR
   END IF
  NEXT i
  IF good THEN
    board(8, 6) = pc(b, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(9, 5) = pc(b, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(8, 4) = pc(b, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(7, 5) = pc(b, i)
    board(8, 5) = b
    IF pc(b, i) <> -board(6, 5) THEN good = 0
    IF good THEN

FOR bl = 1 TO 9
 IF used(bl) = 0 THEN
  used(bl) = 1
  good = 0
  FOR i = 1 TO 4
   IF pc(bl, i) = -board(8, 4) THEN
     good = 1: EXIT FOR
   END IF
  NEXT i
  IF good THEN
    board(8, 3) = pc(bl, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(9, 2) = pc(bl, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(8, 1) = pc(bl, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(7, 2) = pc(bl, i)
    board(8, 2) = bl
    IF good THEN

FOR l = 1 TO 9
 IF used(l) = 0 THEN
  used(l) = 1
  good = 0
  FOR i = 1 TO 4
   IF pc(l, i) = -board(7, 2) THEN
     good = 1: EXIT FOR
   END IF
  NEXT i
  IF good THEN
    board(6, 2) = pc(l, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(5, 1) = pc(l, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(4, 2) = pc(l, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(5, 3) = pc(l, i)
    board(5, 2) = l
    IF pc(l, i) <> -board(5, 4) THEN good = 0
    IF good THEN

FOR tl = 1 TO 9
 IF used(tl) = 0 THEN
  used(tl) = 1
  good = 0
  FOR i = 1 TO 4
   IF pc(tl, i) = -board(4, 2) THEN
     good = 1: EXIT FOR
   END IF
  NEXT i
  IF good THEN
    board(3, 2) = pc(tl, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(2, 1) = pc(tl, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(1, 2) = pc(tl, i): i = i + 1: IF i > 4 THEN i = i - 4
    board(2, 3) = pc(tl, i)
    board(2, 2) = tl
    IF pc(tl, i) <> -board(2, 4) THEN good = 0
    IF good THEN

      FOR row = 1 TO 9
       FOR col = 1 TO 9
        IF (row = 1 OR row = 3 OR row = 4 OR row = 6 OR row = 7 OR row = 9) THEN
         IF col = 2 OR col = 5 OR col = 8 THEN
          PRINT USING "## "; board(row, col);
         ELSE
          PRINT "   ";
         END IF
        ELSE
         IF col MOD 3 = 2 THEN
          PRINT "("; MID$("ABCDEFGHI", board(row, col), 1); ")";
         ELSE
          PRINT USING "## "; board(row, col);
         END IF
        END IF
       NEXT col
       PRINT
      NEXT row
      PRINT

    END IF
  END IF
  used(tl) = 0
 END IF
NEXT tl


    END IF
  END IF
  used(l) = 0
 END IF
NEXT l

    END IF
  END IF
  used(bl) = 0
 END IF
NEXT bl

    END IF
  END IF
  used(b) = 0
 END IF
NEXT b

    END IF
  END IF
  used(br) = 0
 END IF
NEXT br

    END IF
  END IF
  used(r) = 0
 END IF
NEXT r

  END IF
  used(tr) = 0
 END IF
NEXT tr

  END IF
  used(t) = 0
 END IF
NEXT t

 used(ctr) = 0
NEXT ctr

The solutions are listed as:

    1        3        1
-4 (D) 2 -2 (G) 4 -4 (F) 2
   -1       -1       -3
    1        1        3
-2 (E) 3 -3 (A) 4 -4 (C) 1
   -4       -2       -2
    4        2        2
 3 (I)-3  3 (B)-1  1 (H)-3
   -2       -4       -4
    1        3        1
-4 (D) 2 -2 (G) 4 -4 (H) 2
   -1       -1       -3
    1        1        3
-2 (E) 3 -3 (A) 4 -4 (C) 1
   -4       -2       -2
    4        2        2
 3 (I)-3  3 (B)-1  1 (F)-3
   -2       -4       -4
    1        3        1
-4 (H) 2 -2 (I) 4 -4 (D) 2
   -3       -3       -1
    3        3        1
-4 (B) 2 -2 (G) 4 -4 (F) 2
   -1       -1       -3
    1        1        3
-2 (E) 3 -3 (A) 4 -4 (C) 1
   -4       -2       -2
    1        3        1
-4 (F) 2 -2 (I) 4 -4 (D) 2
   -3       -3       -1
    3        3        1
-4 (B) 2 -2 (G) 4 -4 (H) 2
   -1       -1       -3
    1        1        3
-2 (E) 3 -3 (A) 4 -4 (C) 1
   -4       -2       -2

  Posted by Charlie on 2005-12-11 19:25:20
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