AddPage(); #--- Print 50 scrambles. for( $s=0; $s<50; $s++ ){ #--- Get the scramble and adjust the font size. $scramble = scramble(); $pdf->SetFont( 'Courier' , '' , 750 / strlen($scramble) ); #--- Define the cell border. $border = ""; if( $s % 5 == 0 ) $border .= "T"; if( $s % 5 == 4 ) $border .= "B"; #--- Print the scramble. $pdf->Cell( 0, 5, $scramble, $border, 1, "R" ); } } #--- Output the PDF document. $pdf->Output( "scramble3x3.pdf", "I" ); #------------------------------------------------------------------------- function scramble () { #------------------------------------------------------------------------- $faces = array( 'U', 'D', 'L', 'R', 'F', 'B' ); $dirs = array( "", "'", "2" ); foreach( range( 1, 25 ) as $t ){ #--- Find face to turn. do { $turn = rand( 0, 5 ); } while( $bad[$turn] == 1 ); #--- Add the turn. $out .= $faces[$turn] . $dirs[rand(0,2)] . ' '; #--- Mark the face as unavailable. $bad[$turn] = 1; #--- Mark all adjacent faces as available. foreach( range( 0, 5 ) as $i ) if( $i != $turn && ($i^1) != $turn ) $bad[$i] = 0; } return trim( $out ); } ?>