Location: PHPKode > scripts > NSGSC > nsgsc/qubit.php
<?
error_reporting('E_NONE');
echo "<pre>";
class qbit {
	public function genList($n){
		$combo	= pow(2,$n);
		$fin = 1;
		$i = 1;
		$list = array();
		while($i <= $combo){
			$value = "";			
			for($j = 1; $j <= $n; $j++){	//
				$value .= rand(0,1);		// not proud of this part....   
			}								// but again...  the number of atoms wont 
			if(!in_array($value, $list)){	// be so big to cause any harm...
				$list[$i] = $value;			//
				$i++;						//  i hope
			}								//
		}
		sort($list);
		foreach($list as $k => $v){
			$elist[$k]['s'] = '+';
			$elist[$k]['n'] = $v;
		}
		return $elist;
	}
	public function gerPairs($p, $n){
		$p = explode("|", $p);
			foreach($p as $pa){
			$pa = explode(",",$pa);
			$pairs[] = $pa;
			if($pa[0] > $n || $pa[1] > $n)
				die("How am i supposed to get the vertice of a non existent qubit? Do you have a problem or something? (in case you dont get it, this is an error)\n\n<a href=\"?\">Do it again!</a>");
		}
		return $pairs;	
	}
	public function doTheJob($pairs, $list){
		foreach($pairs as $p){
			foreach($list as $k => $la){
				if(substr($la['n'], $p[0]-1, 1) == 1 && substr($la['n'], $p[1]-1, 1) == 1){
					if($la['s'] == "+"){
						$la['s'] = "-";
					}else{
						$la['s'] = "+";
					}
				}
				$list[$k] = $la;
			}
		}
		return $list;
	}
	public function format($pairs, $list){
		
		echo "
		
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\ NSGSC 1.0
\\\\ Not Sexy Graph State Calculator
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\n
";
		foreach($pairs as $p){
				echo "Edge $p[0] $p[1]\n";
			}
		echo "\n\n";
		$i = 0;
		foreach($list as $l){
			if($i == 9){
				echo "\n";
				$i = 0;
			}
			echo "$l[s]|$l[n]>";
			$i++;
		}
	}
	
}
if($_GET['run'] == 1){
	$qbit = new qbit();
	$pairs = $qbit->gerPairs($_GET['p'], $_GET['n']);
	$list = $qbit->genList($_GET['n']);
	$list = $qbit->doTheJob($pairs, $list);
	$list = $qbit->format($pairs, $list);
echo "\n\n<a href=\"?\">Do it again!</a>";
echo "</pre>";
die();
}
?>
<script>
	var atom = prompt("Please state the qubit number:");
	var num = prompt("To define the edges please state the vertices: \neg. 1,2|3,4|5,6 will define 3 edges 1,2 will define 1 edge.");
	var goa = "?n="+atom+"&p="+num+"&run=1";

	document.location = goa;
	</script>

Return current item: NSGSC