From: Bob Smith <uunet!wci.com!bsmith>

Hi,

Patchwork of a hack of a kludge. Worth every penny of what

you're paying for it.

/*

*

  1. Rubik's Tangle (#4)
  2. The puzzle consists of 25 square pieces which are to be arranged in
  3. a 5 by 5 grid such that each edge matches the edge of an adjoining
  4. piece. Each piece has 4 sides and each side has 2 ordered colors.
  5. The idea is to match Red-to-Red and Blue-to-Blue, ...

#

  1. Since the pieces are square they may be rotated to fit as needed.

#

  1. The 25 pieces are listed below. The listing shows the 'straight'
  2. piece vertical and the 'loop' opening to the left. The colors are
  3. shown clockwise starting from the top

# 1 brgbrygy 2 bgybgryr 3 rygrybgb 4 rybrygbg 5 ybrybgrg 6 gybgyrbr 7 gbygbryr 8 rgyrgbyb 9 ybgybrgr 10 bygbyrgr 11 grygrbyb 12 rbgrbygy 13 yrbyrgbg 14 rbyrbgyg 15 gyrgybrb 16 gybgyrbr 17 brybrgyg 18 ygrygbrb 19 bgrbgyry 20 gbrgbyry 21 yrgyrbgb 22 grbgryby 23 rgbrgyby 24 byrbygrg 25 ygbygrbr * * Since there are twelve possible combination of colors on each edge of each piece, we substitue the possible color combinations with hex digits as

follows

"yg"("0"); "yr"("1"); "yb"("2"); "gy"("3"); "gr"("4"); "gb"("5"); "ry"("6"); "rg"("7"); "rb"("8"); "by"("9"); "bg"("A"); "br"("B");

We will define pieces 1 to 25 to be the above; pieces 26 to 50 to be the above pieces rotated clockwise one turn; pieces 51 to 75 ....

The solution matrix is as follows.

1 2 3 4 5 6 7 8 9 10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

  1. include <stdio.h>
  2. include <signal.h>

char *pieces26? = {

" ", /* lets piece # equal array index */ "brgbrygy", "bgybgryr", "rygrybgb", "rybrygbg", "ybrybgrg", "gybgyrbr", "gbygbryr", "rgyrgbyb", "ybgybrgr", "bygbyrgr", "grygrbyb", "rbgrbygy", "yrbyrgbg", "rbyrbgyg", "gyrgybrb", "gybgyrbr", "brybrgyg", "ygrygbrb", "bgrbgyry", "gbrgbyry", "yrgyrbgb", "grbgryby", "rgbrgyby", "byrbygrg", "ygbygrbr",

};

/* the loop variables */ int i01,i02,i03,i04,i05,i06,i07,i08,i09,i10; int i11,i12,i13,i14,i15,i16,i17,i18,i19,i20; int i21,i22,i23,i24,i25;

void current_state(); void wakeup();

main() {

int i,n; char edge101?5?; /* the fifth field is a 'used' flag ('T' or 'F') */

/* Uncomment the following to see a 'status' every minute */ /*if (signal(SIGALRM, wakeup) != 0)

printf("Alarm timer not set!!! Continuing...\n");

(void) alarm(60); */

/* convert the original string patterns to edge patterns */

for (i=1; i<=25; i++) {

for (n=0; n<4; n++) {

if (!strncmp(piecesi?+(n*2), "yg", 2)) edgei?n? = '0'; else if (!strncmp(piecesi?+(n*2), "yr", 2)) edgei?n? = '1'; else if (!strncmp(piecesi?+(n*2), "yb", 2)) edgei?n? = '2'; else if (!strncmp(piecesi?+(n*2), "gy", 2)) edgei?n? = '3'; else if (!strncmp(piecesi?+(n*2), "gr", 2)) edgei?n? = '4'; else if (!strncmp(piecesi?+(n*2), "gb", 2)) edgei?n? = '5'; else if (!strncmp(piecesi?+(n*2), "ry", 2)) edgei?n? = '6'; else if (!strncmp(piecesi?+(n*2), "rg", 2)) edgei?n? = '7'; else if (!strncmp(piecesi?+(n*2), "rb", 2)) edgei?n? = '8'; else if (!strncmp(piecesi?+(n*2), "by", 2)) edgei?n? = '9'; else if (!strncmp(piecesi?+(n*2), "bg", 2)) edgei?n? = 'A'; else if (!strncmp(piecesi?+(n*2), "br", 2)) edgei?n? = 'B';

} /* do the rotations */ edgei?4? = 'F'; edgei+25?0? = edgei?1?; edgei+25?1? = edgei?2?; edgei+25?2? = edgei?3?; edgei+25?3? = edgei?0?; edgei+25?4? = 'F'; edgei+50?0? = edgei?2?; edgei+50?1? = edgei?3?; edgei+50?2? = edgei?0?; edgei+50?3? = edgei?1?; edgei+50?4? = 'F'; edgei+75?0? = edgei?3?; edgei+75?1? = edgei?0?; edgei+75?2? = edgei?1?; edgei+75?3? = edgei?2?; edgei+75?4? = 'F';

}

/* replace the bottom and left edges with the 'matching' edge needed / / on the top or right edge. Thus 'yg' on the top matches bottom 'gy'.*/ for (i=1; i<=100; i++) {

for (n=2; n<=3; n++) {

if (edgei?n? == '0') edgei?n? = '3'; else if (edgei?n? == '1') edgei?n? = '6'; else if (edgei?n? == '2') edgei?n? = '9'; else if (edgei?n? == '3') edgei?n? = '0'; else if (edgei?n? == '4') edgei?n? = '7'; else if (edgei?n? == '5') edgei?n? = 'A'; else if (edgei?n? == '6') edgei?n? = '1'; else if (edgei?n? == '7') edgei?n? = '4'; else if (edgei?n? == '8') edgei?n? = 'B'; else if (edgei?n? == '9') edgei?n? = '2'; else if (edgei?n? == 'A') edgei?n? = '5'; else if (edgei?n? == 'B') edgei?n? = '8';

}

}

/* OK, Here we have 25 nested loops to do the search */ for (i01=1; i01<=100; i01++) {

edgei01%25?4?='T';

for (i02=1; i02<=100; i02++) {

if (edgei02%25?4? == 'T') continue; if (edgei01?1? != edgei02?3?) continue; edgei02%25?4?='T';

for (i03=1; i03<=100; i03++) {

if (edgei03%25?4? == 'T') continue; if (edgei02?1? != edgei03?3?) continue; edgei03%25?4?='T';

for (i04=1; i04<=100; i04++) {

if (edgei04%25?4? == 'T') continue; if (edgei03?1? != edgei04?3?) continue; edgei04%25?4?='T';

for (i05=1; i05<=100; i05++) {

if (edgei05%25?4? == 'T') continue; if (edgei04?1? != edgei05?3?) continue; edgei05%25?4?='T';

for (i06=1; i06<=100; i06++) {

if (edgei06%25?4? == 'T') continue; if (edgei01?2? != edgei06?0?) continue; edgei06%25?4?='T';

for (i07=1; i07<=100; i07++) {

if (edgei07%25?4? == 'T') continue; if (edgei06?1? != edgei07?3?) continue; if (edgei02?2? != edgei07?0?) continue; edgei07%25?4?='T';

for (i08=1; i08<=100; i08++) {

if (edgei08%25?4? == 'T') continue; if (edgei07?1? != edgei08?3?) continue; if (edgei03?2? != edgei08?0?) continue; edgei08%25?4?='T';

for (i09=1; i09<=100; i09++) {

if (edgei09%25?4? == 'T') continue; if (edgei08?1? != edgei09?3?) continue; if (edgei04?2? != edgei09?0?) continue; edgei09%25?4?='T';

for (i10=1; i10<=100; i10++) {

if (edgei10%25?4? == 'T') continue; if (edgei09?1? != edgei10?3?) continue; if (edgei05?2? != edgei10?0?) continue; edgei10%25?4?='T';

for (i11=1; i11<=100; i11++) {

if (edgei11%25?4? == 'T') continue; if (edgei06?2? != edgei11?0?) continue; edgei11%25?4?='T';

for (i12=1; i12<=100; i12++) {

if (edgei12%25?4? == 'T') continue; if (edgei11?1? != edgei12?3?) continue; if (edgei07?2? != edgei12?0?) continue; edgei12%25?4?='T';

for (i13=1; i13<=100; i13++) {

if (edgei13%25?4? == 'T') continue; if (edgei12?1? != edgei13?3?) continue; if (edgei08?2? != edgei13?0?) continue; edgei13%25?4?='T';

for (i14=1; i14<=100; i14++) {

if (edgei14%25?4? == 'T') continue; if (edgei13?1? != edgei14?3?) continue; if (edgei09?2? != edgei14?0?) continue; edgei14%25?4?='T';

for (i15=1; i15<=100; i15++) {

if (edgei15%25?4? == 'T') continue; if (edgei14?1? != edgei15?3?) continue; if (edgei10?2? != edgei15?0?) continue; edgei15%25?4?='T';

for (i16=1; i16<=100; i16++) {

if (edgei16%25?4? == 'T') continue; if (edgei11?2? != edgei16?0?) continue; edgei16%25?4?='T';

for (i17=1; i17<=100; i17++) {

if (edgei17%25?4? == 'T') continue; if (edgei16?1? != edgei17?3?) continue; if (edgei12?2? != edgei17?0?) continue; edgei17%25?4?='T';

for (i18=1; i18<=100; i18++) {

if (edgei18%25?4? == 'T') continue; if (edgei17?1? != edgei18?3?) continue; if (edgei13?2? != edgei18?0?) continue; edgei18%25?4?='T';

for (i19=1; i19<=100; i19++) {

if (edgei19%25?4? == 'T') continue; if (edgei18?1? != edgei19?3?) continue; if (edgei14?2? != edgei19?0?) continue; edgei19%25?4?='T';

for (i20=1; i20<=100; i20++) {

if (edgei20%25?4? == 'T') continue; if (edgei19?1? != edgei20?3?) continue; if (edgei15?2? != edgei20?0?) continue; edgei20%25?4?='T';

for (i21=1; i21<=100; i21++) {

if (edgei21%25?4? == 'T') continue; if (edgei16?2? != edgei21?0?) continue; edgei21%25?4?='T';

for (i22=1; i22<=100; i22++) {

if (edgei22%25?4? == 'T') continue; if (edgei21?1? != edgei22?3?) continue; if (edgei17?2? != edgei22?0?) continue; edgei22%25?4?='T';

for (i23=1; i23<=100; i23++) {

if (edgei23%25?4? == 'T') continue; if (edgei22?1? != edgei23?3?) continue; if (edgei18?2? != edgei23?0?) continue; edgei23%25?4?='T';

for (i24=1; i24<=100; i24++) {

if (edgei24%25?4? == 'T') continue; if (edgei23?1? != edgei24?3?) continue; if (edgei19?2? != edgei24?0?) continue; edgei24%25?4?='T';

for (i25=1; i25<=100; i25++) {

if (edgei25%25?4? == 'T') continue; if (edgei24?1? != edgei25?3?) continue; if (edgei20?2? != edgei25?0?) continue; edgei25%25?4?='T'; printf("Solution: "); current_state();

edgei25%25?4?'F';} edgei24%25?4?'F';} edgei23%25?4?'F';} edgei22%25?4?'F';} edgei21%25?4?'F';} edgei20%25?4?'F';} edgei19%25?4?'F';} edgei18%25?4?'F';} edgei17%25?4?'F';} edgei16%25?4?'F';} edgei15%25?4?'F';} edgei14%25?4?'F';} edgei13%25?4?'F';} edgei12%25?4?'F';} edgei11%25?4?'F';} edgei10%25?4?'F';} edgei09%25?4?'F';} edgei08%25?4?'F';} edgei07%25?4?'F';} edgei06%25?4?'F';} edgei05%25?4?'F';} edgei04%25?4?'F';} edgei03%25?4?'F';} edgei02%25?4?'F';} edgei01%25?4?='F';}

exit(1);

}

void wakeup() {

current_state(); if (signal(SIGALRM, wakeup) != 0)

printf("Alarm timer not set!!! Continuing...\n");

(void) alarm(600);

}

void current_state() {

printf("%d,%1d ", i01%25, i01/25); printf("%d ", i02%25); printf("%d ", i03%25); printf("%d ", i04%25); printf("%d ", i05%25); printf("%d ", i06%25); printf("%d ", i07%25); printf("%d ", i08%25); printf("%d ", i09%25); printf("%d ", i10%25); printf("%d ", i11%25); printf("%d ", i12%25); printf("%d ", i13%25); printf("%d ", i14%25); printf("%d ", i15%25); printf("%d ", i16%25); printf("%d ", i17%25); printf("%d ", i18%25); printf("%d ", i19%25); printf("%d ", i20%25); printf("%d ", i21%25); printf("%d ", i22%25); printf("%d ", i23%25); printf("%d ", i24%25); printf("%d\n",i25%25); return;

}

/*

Solution: 19,0 6 18 23 9 0 5 21 11 24 20 2 4 15 22 13 3 7 1 16 10 17 12 8 14 Solution: 19,0 16 18 23 9 0 5 21 11 24 20 2 4 15 22 13 3 7 1 6 10 17 12 8 14 Solution: 9,1 24 22 6 14 23 11 15 1 8 18 21 4 7 12 16 5 2 3 17 19 0 20 13 10 Solution: 9,1 24 22 16 14 23 11 15 1 8 18 21 4 7 12 6 5 2 3 17 19 0 20 13 10 Solution: 14,1 8 12 17 10 6 1 7 3 13 22 15 4 2 20 24 11 21 5 0 9 23 18 16 19 Solution: 14,1 8 12 17 10 16 1 7 3 13 22 15 4 2 20 24 11 21 5 0 9 23 18 6 19 Solution: 1,2 11 12 17 3 21 5 23 15 2 20 6 18 13 10 0 24 22 7 19 16 8 9 14 4 Solution: 1,2 11 12 17 3 21 5 23 15 2 20 16 18 13 10 0 24 22 7 19 6 8 9 14 4 Solution: 10,2 13 20 0 19 17 3 2 5 6 12 7 4 21 18 8 1 15 11 23 14 16 22 24 9 Solution: 10,2 13 20 0 19 17 3 2 5 16 12 7 4 21 18 8 1 15 11 23 14 6 22 24 9 Solution: 3,3 2 10 19 4 17 15 13 7 14 12 23 18 22 9 11 5 6 24 8 1 21 20 0 16 Solution: 3,3 2 10 19 4 17 15 13 7 14 12 23 18 22 9 11 5 16 24 8 1 21 20 0 6 Solution: 4,3 14 9 8 6 19 7 22 24 0 10 13 18 16 20 2 15 23 5 21 3 17 12 11 1 Solution: 4,3 14 9 8 16 19 7 22 24 0 10 13 18 6 20 2 15 23 5 21 3 17 12 11 1 Solution: 6,3 0 20 21 1 8 24 16 5 11 9 22 18 23 12 14 7 13 15 17 4 19 10 2 3 Solution: 16,3 0 20 21 1 8 24 6 5 11 9 22 18 23 12 14 7 13 15 17 4 19 10 2 3

lib/DbaDatabase.php:134: Warning: dba_replace() [<a href='function.dba-replace'>function.dba-replace</a>]: You cannot perform a modification to a database without proper access