All pastes #41744 Raw Edit

Mine

public php v1 · immutable
#41744 ·published 2006-02-15 14:20 UTC
rendered paste body
<?php$queens = 7;$first_x = rand(0,7);$first_y = rand(0,7);echo "Placing a queen at $first_x x $first_y<br>";$cb[$first_x][$first_y] = true;echo isQueen($first_x, $first_y); while(1) {  $last_x = rand(0,7);  $last_y = rand(0,7);  echo "Wanna place a queen at $last_x x $last_y<br>";  if(noCrash($last_x, $last_y)) { $cb[$last_x][$last_y] = true; }  $i++;  if($i == $queens) { echo "Done"; break; }}function noCrash($x, $y) {  ###########################################################################  echo "Starting checking if any queens are on the same - row as ".$x."x".$y."<br>";  $go_x = 0;  while($go_x <= 7) {    if(isQueen($x, $go_x)) { return false; }	else { $go_x++; }  }  ###########################################################################  echo "Starting checking if any queens are on the same | row as ".$x."x".$y."<br>";  $go_y = 0;  while($go_y <= 7) {    if(isQueen($x, $go_y)) { return false; }	else { $go_y++; }  }  ###########################################################################  echo "Starting checking if any queens are on the same \ row as ".$x."x".$y."<br>";    $go_y = $y; $go_x = $x;    if($x < $y) { $go_y -= $go_x; $go_x = 0; }  elseif($y > $x) { $go_x -= $go_y; $go_y = 0; }  elseif($x == $y) { $go_x = 0; $go_y = 0; }    while($go_x <= 7 && $go_y <= 7) {    if(isQueen($go_x, $go_y)) { return false; }	else { $go_x++; $go_y++; }  }  ###########################################################################  echo "Starting checking if any queens are on the same / row as ".$x."x".$y."<br>";  $go_y = $y; $go_x = $x;    if($x < $y) { $go_y -= $go_x; $go_x = 0; }  elseif($y > $x) { $go_x -= $go_y; $go_y = 7; }  elseif($x == $y) { $go_x = 0; $go_y = 7; }    while($go_x <= 7 && $go_y >= 0) {    if(isQueen($go_x, $go_y)) { return false; }	else { $go_x++; $go_y--; }  }  ###########################################################################  return true;}function isQueen($x,$y) { if(($cb[$x][$y]?1:0) == 1) { echo "TRUE"; return true; } else { return false; } }?><br /><br /><h1>Chess Board</h1><table border=1><?php  $x = 0;  $y = 0;  while($y <= 7) {    echo "<tr>";	$x = 0;	if($color == 1) { $color = 2; } else { $color = 1; }	while($x <= 7) {	  if($color == 1) { $col = "black"; $color = 2; } else { $col = "white"; $color = 1; }	  $queen =($cb[$x][$y]?1:0);	  if($queen) { $col = "red"; }	  echo "<td style='width: 50px; height: 50px; background-color: $col'>&nbsp;</td>"; 	  $x++; 	}	echo "</tr>";	$y++;  }?></table><?php var_dump($cb); ?>