function savepuzzle(&$crossm, &$crossd, $ctries, $time)
 {
     $N22 = $this->m_best_N20 + 2;
     $cols = $this->m_maxcol - $this->m_mincol + 1;
     $rows = $this->m_maxrow - $this->m_minrow + 1;
     //if( $cols < $rows)
     //  $bSwapColRow = 1;
     //else
     $bSwapColRow = 0;
     if ($bSwapColRow) {
         Swap($cols, $rows);
         Swap($this->m_mincol, $this->m_minrow);
         Swap($this->m_maxcol, $this->m_maxrow);
     }
     $crossm->datebegin = time();
     $crossm->time = $time;
     $crossm->cols = $cols;
     $crossm->rows = $rows;
     $crossm->words = count($this->m_best_cross_pos);
     $crossm->wordsall = count($this->m_input_answers);
     $crossm->createscore = $this->m_best_score;
     $crossm->createtries = $ctries;
     $crossm->createtimelimit = $this->m_time_limit;
     $crossm->createconnectors = $this->m_best_connectors;
     $crossm->createfilleds = $this->m_best_filleds;
     $crossm->createspaces = $this->m_best_spaces;
     for ($i = 0; $i < count($this->m_best_cross_pos); $i++) {
         $pos = $this->m_best_cross_pos[$i];
         $col = $pos % $N22;
         $row = floor(($pos - $col) / $N22);
         $col += -$this->m_mincol + 1;
         $row += -$this->m_minrow + 1;
         $dir = $this->m_best_cross_dir[$i];
         $word = $this->m_best_cross_word[$i];
         $word = substr($word, 1, strlen($word) - 2);
         unset($rec);
         $rec->col = $col;
         $rec->row = $row;
         $rec->horizontal = $dir == "h" ? 1 : 0;
         $rec->answertext = $word;
         $rec->questiontext = $this->m_input_answers[$word];
         if ($rec->horizontal) {
             $key = sprintf('h%10d %10d', $rec->row, $rec->col);
         } else {
             $key = sprintf('v%10d %10d', $rec->col, $rec->row);
         }
         $crossd[$key] = $rec;
     }
     if (count($crossd) > 1) {
         ksort($crossd);
     }
     return count($crossd) > 0;
 }
Esempio n. 2
0
<?php

/**
 * Write a procedure Swap(X, Y) that exchanges the values
 * of variables X and Y (X and Y are input and output real-valued parameters).
 * Having input integers A, B, C, D and using three calls of this procedure,
 * sequentially exchange the values of the pairs A and B, C and D, B and C.
 * Output the new values of A, B, C, D.
 */
function Swap(&$X, &$Y)
{
    $var = $X;
    $X = $Y;
    $Y = $var;
}
$A = 12;
$B = 13;
$C = 14;
$D = 15;
echo 'A &nbsp = &nbsp ' . $A . ',&nbsp B =&nbsp' . $B . ', C &nbsp = &nbsp ' . $C . ',&nbsp D = &nbsp' . $D . '<br/>';
Swap($A, $B);
echo 'A &nbsp = &nbsp ' . $A . ',&nbsp B =&nbsp' . $B . ', C &nbsp = &nbsp ' . $C . ',&nbsp D = &nbsp' . $D . '<br/>';
Swap($C, $D);
echo 'A &nbsp = &nbsp ' . $A . ',&nbsp B =&nbsp' . $B . ', C &nbsp = &nbsp ' . $C . ',&nbsp D = &nbsp' . $D . '<br/>';
Swap($B, $C);
echo 'A &nbsp = &nbsp ' . $A . ',&nbsp B =&nbsp' . $B . ', C &nbsp = &nbsp ' . $C . ',&nbsp D = &nbsp' . $D . '<br/>';