[ create a new paste ] login | about

Link: http://codepad.org/UtjNt7qV    [ raw code | output | fork ]

PHP, pasted on Jan 29:
<?php
class K{
	protected $serial;
	protected $freq;
	function __construct($s,$f){
		$this->serial=$s;
		$this->freq=$f;
	}
	function I($k){
		return $this->freq === $k->freq;
	}
	function serial(){
		return $this->serial;
	}
	function __toString(){
		return str_pad($this->serial,2,' ',0).'-'.$this->freq.' ';
	}
}

function O($K){
	$O=array(array(),array(),array());
	foreach($K as $v){
		foreach($O as &$d){
			if(!$d||$v->I($d[0])){
				$d[]=$v;
				break;
			}
		}
	}
	$i=6;while($i--){
		$j=6;while($j--){
			$v=$j%3+$i%3;
			$v>2&&$v-=3;
			echo array_pop($O[$v]).' ';
		}
		echo "\n";
	}
}


$k = array();
for($i=0;$i<36;$i++){
	$k[] = new K($i, $i%3);
}
shuffle($k);
O($k);


Output:
1
2
3
4
5
6
28-1  30-0  20-2  10-1  21-0  23-2  
 0-0  26-2   1-1   3-0  29-2  31-1  
17-2  19-1  18-0  11-2  34-1  33-0  
 7-1   6-0  32-2  16-1   9-0   2-2  
12-0  14-2  25-1  24-0  35-2  13-1  
 5-2  22-1  15-0   8-2   4-1  27-0  


Create a new paste based on this one


Comments: