Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $colors = array(
- 1 => 'R',
- 2 => 'O',
- 4 => 'Y',
- 8 => 'G',
- 16 => 'B',
- 32 => 'P',
- false => 'X',
- );
- $used_towers = array_fill(0, 6, 0);
- $cube = array(
- array(1,3,4,5,2,0),
- array(2,5,1,4,1,3),
- array(0,1,3,2,5,4),
- array(5,4,0,3,0,2),
- array(4,2,5,0,3,1),
- array(3,0,2,1,4,5),
- );
- $solution = array_fill(0, 6, array_fill(0, 6, false));
- $solutions = array( );
- function test_color($pos, $solution, $used_towers, $color, $size) {
- if (36 <= $pos) {
- return false;
- }
- // check if piece exists in solution at this location
- if (false !== $solution[floor($pos / 6)][$pos % 6]) {
- return false;
- }
- // check if tower of this size and color has already been used
- if ($color & $used_towers[$size]) {
- return false;
- }
- // check if tower has already been used in row or column:
- for ($i = 0; $i < 6; ++$i) {
- if ($color == $solution[floor($pos / 6)][$i]) {
- return false;
- }
- if ($color == $solution[$i][$pos % 6]) {
- return false;
- }
- }
- // special conditions for the two special towers
- if (array(1, 2) == (array(floor($pos / 6), $pos % 6)) && (4 != $color)) {
- return false;
- }
- if (array(3, 2) == (array(floor($pos / 6), $pos % 6)) && (2 != $color)) {
- return false;
- }
- return true;
- }
- function print_solution($solution) {
- global $colors, $cube;
- echo "<br>\n";
- for ($i = 0; $i < 6; ++$i) {
- for ($j = 0; $j < 6; ++$j) {
- echo '('.$colors[$solution[$i][$j]].', '.(6 - $cube[$i][$j]).'), ';
- }
- echo "<br>\n";
- }
- echo "<br>\n";
- }
- function solve($pos, $solution, $used_towers, $best, $color) {
- global $colors, $cube;
- if (36 == $pos) {
- return array($best, $solution);
- }
- $size = $cube[floor($pos / 6)][$pos % 6];
- if (test_color($pos, $solution, $used_towers, $color, $size)) {
- $used_towers[$size] |= $color;
- $solution[floor($pos / 6)][$pos % 6] = $color;
- if ($pos > $best) {
- echo '####### '.($pos + 1).' towers placed';
- print_solution($solution, $colors, $cube);
- $best = $pos;
- }
- list($best, $solution) = solve($pos + 1, $solution, $used_towers, $best, $color);
- if (35 <= $best) {
- return array($best, $solution);
- }
- $solution[floor($pos / 6)][$pos % 6] = false;
- $used_towers[$size] ^= $color;
- }
- return array($best, $solution);
- }
- function solve_color($color) {
- global $solution, $used_towers, $colors, $cube;
- $orig = $solution;
- $failed = array( );
- $i = 0;
- $j = -1;
- while ($i <= 5) {
- // if we already have a piece in this space (via pre-reqs)
- // just skip it
- if (in_array($color, $orig[$i])) {
- $i++;
- $j = -1;
- continue;
- }
- if ( ! isset($failed[$i])) {
- $failed[$i] = array( );
- }
- do {
- $j++;
- $size = $cube[$i][$j];
- // we've already tried this one, try the next space
- } while (in_array($size, $failed[$i]) && (5 > $j));
- // try putting a piece in the ith row in the last + 1 col
- if (test_color(($i * 6) + $j, $solution, $used_towers, $color, $size) && ! in_array($size, $failed[$i])) {
- $solution[$i][$j] = $color;
- $used_towers[$size] |= $color;
- $i++;
- $j = -1;
- continue;
- }
- // something failed, go back a row and try a new piece
- if (5 <= $j) {
- // backtrack until we find a row that didn't already have a piece in it
- do {
- $i--;
- } while (in_array($color, $orig[$i]));
- // find out what piece was used here
- foreach ($solution[$i] as $j => $col) {
- if ($color == $col) {
- $size = $cube[$i][$j];
- $failed[$i][] = $size;
- $used_towers[$size] ^= $color;
- }
- }
- $solution[$i] = $orig[$i];
- $j = -1;
- continue;
- }
- }
- return $solution;
- }
- #$color = 4;
- #$solution[1][2] = $color;
- #$size = $cube[1][2];
- #$used_towers[$size] |= $color;
- #debug(solve_color($color));
- function filter_color($used, $color) {
- foreach ($used as & $row) {
- $row = (bool) ($color & $row);
- }
- unset($row);
- return array_filter($used);
- }
- function solve_color_by_pieces($color, $solution, $used_towers, $continue_colors = false, $top = false) {
- global $colors, $cube;
- $orig = $solution;
- $sols = array( );
- while (32 >= $color) {
- $size = 0;
- while (6 >= count(filter_color($used_towers, $color)) && (5 >= $size)) {
- if ($color & $used_towers[$size]) {
- $size++;
- continue;
- }
- // find ALL possible solutions for this size
- for ($pos = 0; $pos < 36; ++$pos) {
- if ($size != $cube[floor($pos / 6)][$pos % 6]) {
- continue;
- }
- if ( ! test_color($pos, $solution, $used_towers, $color, $size)) {
- continue;
- }
- // add to this solution path and continue...
- $solution[floor($pos / 6)][$pos % 6] = $color;
- $used_towers[$size] |= $color;
- $return = ((6 > count(filter_color($used_towers, $color))) ? solve_color_by_pieces($color, $solution, $used_towers, $continue_colors) : array('SOLUTION' => $solution));
- if ($return) {
- $sols[] = $return;
- }
- // remove this solution and continue searching this level
- $solution[floor($pos / 6)][$pos % 6] = false;
- $used_towers[$size] ^= $color;
- }
- break;
- }
- if ($top) {
- debug($sols);
- unset($sols);
- $sols = array( );
- }
- if ($continue_colors) {
- $color << 1;
- }
- else {
- break;
- }
- }
- return $sols;
- }
- function find_sols($sols, $color) {
- foreach ($sols as $key => $sol) {
- if ('SOLUTION' === $key) {
- foreach ($sol as $i => $row) {
- foreach ($row as $j => $piece) {
- if ($color == $piece) {
- echo '$solution['.$i.']['.$j.'] = ';
- }
- }
- }
- echo "<br>\n";
- }
- elseif (is_array($sol)) {
- find_sols($sol, $color);
- }
- }
- }
- #$color = 4;
- #$solution[1][2] = $color;
- #$size = $cube[1][2];
- #$used_towers[$size] |= $color;
- #debug(solve_color_by_pieces($color, $solution, $used_towers));
- // set up the yellow in the first of the two solutions and solve for orange
- #$solution[0][3] = $solution[1][2] = $solution[2][5] = $solution[3][4] = $solution[4][1] = $solution[5][0] = 4; // yellow
- #$color = 1;
- #$solution[3][2] = $color;
- #$size = $cube[3][2];
- #$used_towers[$size] |= $color;
- #debug(solve_color_by_pieces($color, $solution, $used_towers));
- /*
- Yellow and orange = 2 solutions (both same footprint, so multiply final answer by 2)
- */
- // solve for red
- $solution[0][3] = $solution[1][2] = $solution[2][5] = $solution[3][4] = $solution[4][1] = $solution[5][0] = 4; // yellow
- $solution[0][1] = $solution[1][4] = $solution[2][3] = $solution[3][2] = $solution[4][0] = $solution[5][5] = 2; // orange
- #$color = 1;
- #debug($solutions = solve_color_by_pieces($color, $solution, $used_towers, false));
- #find_sols($solutions, $color);
- /*
- Red = 8 solutions
- */
- // red solutions
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 1; // A - C,F,H
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 1; // B - D,E,G
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 1; // C - A,F,H
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 1; // D - B,E,G
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 1; // E - B,D,G
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 1; // F - A,C,H
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 1; // G - B,D,E
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 1; // H - A,C,F
- // solve for green
- #$color = 8;
- #debug($solutions = solve_color_by_pieces($color, $solution, $used_towers, false));
- #find_sols($solutions, $color);
- /*
- Green = 3 solutions each red = 24 solutions
- but there are only 8 unique solutions
- although when matched up with the 8 red solutions they may make different footprints
- */
- // green solutions
- // A
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 8; // H
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 8; // F
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 8; // C
- // B
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 8; // G
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 8; // D
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 8; // E
- // C
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 8; // H
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 8; // F
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 8; // A
- // D
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 8; // G
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 8; // B
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 8; // E
- // E
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 8; // G
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 8; // D
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 8; // B
- // F
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 8; // H
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 8; // A
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 8; // C
- // G
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 8; // D
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 8; // B
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 8; // E
- // H
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 8; // F
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 8; // A
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 8; // C
- // unique solutions for green
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 8; // A - H,F,C
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 8; // B - G,E,D
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 8; // C - H,F,A
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 8; // D - G,E,B
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 8; // E - G,D,B
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 8; // F - H,C,A
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 8; // G - E,D,B
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 8; // H - F,C,A
- // upon further inspection, there are duplicates between the red and green (which should be obvious), which means
- // that only half of the solutions are truly unique (the other half just being swapped colors, red and green)
- // so 12 solutions total, with the unique solutions as follows:
- /*
- AC = AC - CA = CA
- AF = AF - FA = FA
- AH = AH - HA = HA
- BD = BD - DB = DB
- BE = BE - EB = EB
- BG = BG - GB = GB
- CF = CF - FC = FC
- CH = CH - HC = HC
- DE = DE - ED = ED
- DG = DG - GD = GD
- EG = EG - GE = GE
- FH = FH - HF = HF
- */
- // combo solutions
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 1; // A - C,F,H
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 8; // C - H,F,A
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 1; // A - C,F,H
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 8; // F - H,C,A
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 1; // A - C,F,H
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 8; // H - F,C,A
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 1; // B - D,E,G
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 8; // D - G,E,B
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 1; // B - D,E,G
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 8; // E - G,D,B
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 1; // B - D,E,G
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 8; // G - E,D,B
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 1; // C - A,F,H
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 8; // F - H,C,A
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 1; // C - A,F,H
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 8; // H - F,C,A
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 1; // D - B,E,G
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 8; // E - G,D,B
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 1; // D - B,E,G
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 8; // G - E,D,B
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 1; // E - B,D,G
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 8; // G - E,D,B
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 1; // 3 - A,C,H
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 8; // H - F,C,A
- // solve for blue
- #$color = 16;
- #debug($solutions = solve_color_by_pieces($color, $solution, $used_towers, false));
- #find_sols($solutions, $color);
- /*
- Blue = 2 solutions each for a total of 24 as follows:
- AC
- $solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 16; // H
- $solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 16; // F
- AF
- $solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 16; // H
- $solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 16; // C
- AH
- $solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 16; // F
- $solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 16; // C
- BD
- $solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 16; // G
- $solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 16; // E
- BE
- $solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 16; // G
- $solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 16; // D
- BG
- $solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 16; // D
- $solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 16; // E
- CF
- $solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 16; // H
- $solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 16; // A
- CH
- $solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 16; // F
- $solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 16; // A
- DE
- $solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 16; // G
- $solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 16; // B
- DG
- $solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 16; // B
- $solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 16; // E
- EG
- $solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 16; // D
- $solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 16; // B
- FH
- $solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 16; // A
- $solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 16; // C
- only 8 of the solutions are unique though
- $solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 16; // A - FH,CH,CF
- $solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 16; // B - EG,DG,DE
- $solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 16; // C - FH,AH,AF
- $solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 16; // D - EG,BG,BE
- $solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 16; // E - DG,BG,BD
- $solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 16; // F - CH,AH,AC
- $solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 16; // G - DE,BE,BD
- $solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 16; // H - CF,AF,AC
- and when combined with the other two sets, they combine to create only 8 unique solutions
- AFH - FAH - HAF
- ACH - CAH - HAC
- ACF - CAF - FAC
- BEG - EBG - GBE
- BDG - DBG - GBD
- BDE - DBE - EBD
- CFH - FCH - HCF
- DEG - EDG - GDE
- */
- // AFH
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 1; // A - C,F,H
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 8; // F - H,C,A
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 16; // H - CF,AF,AC
- // ACH
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 1; // A - C,F,H
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 8; // C - H,F,A
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 16; // H - CF,AF,AC
- // ACF
- #$solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 1; // A - C,F,H
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 8; // C - H,F,A
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 16; // F - CH,AH,AC
- // BEG
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 1; // B - D,E,G
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 8; // E - G,D,B
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 16; // G - DE,BE,BD
- // BDG
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 1; // B - D,E,G
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 8; // D - G,E,B
- #$solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 16; // G - DE,BE,BD
- // BDE
- #$solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 1; // B - D,E,G
- #$solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 8; // D - G,E,B
- #$solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 16; // E - DG,BG,BD
- // CFH
- #$solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 1; // C - A,F,H
- #$solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 8; // F - H,C,A
- #$solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 16; // H - CF,AF,AC
- // DEG
- $solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 1; // D - B,E,G
- $solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 8; // E - G,D,B
- $solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 16; // G - DE,BE,BD
- // solve for purple
- $color = 32;
- debug($solutions = solve_color_by_pieces($color, $solution, $used_towers, false));
- find_sols($solutions, $color);
- /*
- purple solutions
- obviously, there will only be one solution for each set
- AFH
- $solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 32; // C
- ACH
- $solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 32; // F
- ACF
- $solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 32; // H
- BEG
- $solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 32; // D
- BDG
- $solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 32; // E
- BDE
- $solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 32; // G
- CFH
- $solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 32; // A
- DEG
- $solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 32; // B
- and each solution is unique
- $solution[0][0] = $solution[1][1] = $solution[2][2] = $solution[3][5] = $solution[4][3] = $solution[5][4] = 32; // A - CFH
- $solution[0][0] = $solution[1][5] = $solution[2][4] = $solution[3][1] = $solution[4][3] = $solution[5][2] = 32; // B - DEG
- $solution[0][2] = $solution[1][0] = $solution[2][4] = $solution[3][3] = $solution[4][5] = $solution[5][1] = 32; // C - AFH
- $solution[0][2] = $solution[1][1] = $solution[2][0] = $solution[3][5] = $solution[4][4] = $solution[5][3] = 32; // D - BEG
- $solution[0][4] = $solution[1][3] = $solution[2][2] = $solution[3][0] = $solution[4][5] = $solution[5][1] = 32; // E - BDG
- $solution[0][4] = $solution[1][5] = $solution[2][0] = $solution[3][1] = $solution[4][2] = $solution[5][3] = 32; // F - ACH
- $solution[0][5] = $solution[1][0] = $solution[2][1] = $solution[3][3] = $solution[4][2] = $solution[5][4] = 32; // G - BDE
- $solution[0][5] = $solution[1][3] = $solution[2][1] = $solution[3][0] = $solution[4][4] = $solution[5][2] = 32; // H - ACF
- and when taken as a whole, there are only 2 solutions (with all others being color swaps)
- ACFH - CAFH - FACH - HACF
- BDEG - DBEG - EBDG - GBDE
- and when multiplied by the original 2 yellow and orange solutions, that leaves us with 4 unique solutions.
- QED
- */
- /** function call [dump] [debug]
- * This function is for debugging only
- * Outputs given var to screen
- * or, if no var given, outputs stars to note position
- *
- * @param mixed optional var to output
- * @param bool optional bypass debug value and output anyway
- * @action outputs var to screen
- * @return void
- */
- function call($var = 'Th&F=xUFucreSp2*ezAhe=ApuPR*$axe', $bypass = false, $show_from = true, $new_window = false, $error = false)
- {
- if ((( ! defined('DEBUG') || ! DEBUG) || ! empty($GLOBALS['NODEBUG'])) && ! (bool) $bypass) {
- return false;
- }
- if ('Th&F=xUFucreSp2*ezAhe=ApuPR*$axe' === $var) {
- $contents = '<span style="font-size:larger;font-weight:bold;color:red;">--==((OO88OO))==--</span>';
- }
- else {
- // begin output buffering so we can escape any html
- // and print_r is better at catching recursion than var_export
- ob_start( );
- if ((is_string($var) && ! preg_match('/^\\s*$/', $var))) { // non-whitespace strings
- print_r($var);
- }
- else {
- if ( ! function_exists('xdebug_disable')) {
- if (is_array($var) || is_object($var)) {
- print_r($var);
- }
- else {
- var_dump($var);
- }
- }
- else {
- var_dump($var);
- }
- }
- // end output buffering and output the result
- if ( ! function_exists('xdebug_disable')) {
- $contents = htmlentities(ob_get_contents( ));
- }
- else {
- $contents = ob_get_contents( );
- }
- ob_end_clean( );
- }
- $j = 0;
- $html = '';
- $debug_funcs = array('dump', 'debug');
- if ((bool) $show_from) {
- $called_from = debug_backtrace( );
- if (isset($called_from[$j + 1]) && in_array($called_from[$j + 1]['function'], $debug_funcs)) {
- ++$j;
- }
- $file0 = substr($called_from[$j]['file'], strlen($_SERVER['DOCUMENT_ROOT']));
- $line0 = $called_from[$j]['line'];
- $called = '';
- if (isset($called_from[$j + 1]['file'])) {
- $file1 = substr($called_from[$j + 1]['file'], strlen($_SERVER['DOCUMENT_ROOT']));
- $line1 = $called_from[$j + 1]['line'];
- $called = "{$file1} : {$line1} called ";
- }
- elseif (isset($called_from[$j + 1]['class'])) {
- $called = $called_from[$j + 1]['class'].$called_from[$j + 1]['type'].$called_from[$j + 1]['function'].' called ';
- }
- $html = "<strong>{$called}{$file0} : {$line0}</strong>\n";
- }
- if ( ! $new_window) {
- $color = '#000';
- if ($error) {
- $color = '#F00';
- }
- echo "\n\n<pre style=\"background:#FFF;color:{$color};font-size:larger;\">{$html}{$contents}\n<hr /></pre>\n\n";
- }
- else { ?>
- <script language="javascript">
- myRef = window.open('','debugWindow');
- myRef.document.write('\n\n<pre style="background:#FFF;color:#000;font-size:larger;">');
- myRef.document.write('<?php echo str_replace("'", "\'", str_replace("\n", "<br />", "{$html}{$contents}")); ?>');
- myRef.document.write('\n<hr /></pre>\n\n');
- </script>
- <?php }
- }
- function dump($var = 'Th&F=xUFucreSp2*ezAhe=ApuPR*$axe', $bypass = false, $show_from = true, $new_window = false, $error = false) { call($var, $bypass, $show_from, $new_window, $error); }
- function debug($var = 'Th&F=xUFucreSp2*ezAhe=ApuPR*$axe', $bypass = true, $show_from = true, $new_window = false, $error = false) { call($var, $bypass, $show_from, $new_window, $error); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement