--- /dev/null
+<?php\r
+//Settings\r
+$start = 0;\r
+$stop = 1000;\r
+$places = strlen($stop);\r
+$tryes = 50; //Tryes to find better\r
+$base = 10;\r
+//Init\r
+error_reporting(0);\r
+srand(time());\r
+\r
+/////////////////////////////////////////////////////////////////\r
+//\r
+function rada_add($name, $istr) { //Funkce pro pridani do rady -> !!! OPTIMALIZOVAT !!! <-\r
+ if(!eregi($istr, $GLOBALS[$name])) {\r
+ if( $istr[0] == $GLOBALS[$name][strlen($GLOBALS[$name])-1] ) {\r
+ $istr = substr($istr, 1);\r
+ $GLOBALS[$name] = $GLOBALS[$name].$istr;\r
+ } elseif( $GLOBALS[$name][0] == $istr[strlen($istr)-1] ) { \r
+ $GLOBALS[$name] = substr($GLOBALS[$name], 1);\r
+ $GLOBALS[$name] = $istr.$GLOBALS[$name];\r
+ } else {\r
+\r
+ //Nahodne na zacetek nebo konec\r
+ if(rand(0,1)) { \r
+ $GLOBALS[$name] = $istr.$GLOBALS[$name];\r
+ } else {\r
+ $GLOBALS[$name] = $GLOBALS[$name].$istr;\r
+ }\r
+ \r
+ }\r
+ }\r
+ //$GLOBALS[$name]=$GLOBALS[$name].$istr; //Debug\r
+}\r
+\r
+//\r
+function rada_unique($name) { //Funkce pro vyhledani a smazani duplikatu (i potrebnych)\r
+ $length = $GLOBALS["places"];\r
+ $replacer = "%";\r
+\r
+ for($i=0;$i<(strlen($GLOBALS[$name])-$length);$i++) {\r
+ \r
+ $sub = substr($GLOBALS[$name], $i, $length);\r
+ for($x=0;$x<$length;$x++) {\r
+ $GLOBALS[$name][($i+$x)] = $replacer;\r
+ }\r
+ \r
+ $GLOBALS[$name] = str_replace($sub, "", $GLOBALS[$name]); //Smaze duplikaty\r
+ \r
+ $replace="";\r
+ for($x=0;$x<$length;$x++) {\r
+ $replace = $replace.$replacer;\r
+ }\r
+ \r
+ $GLOBALS[$name] = str_replace($replace, $sub, $GLOBALS[$name]);\r
+ }\r
+\r
+}\r
+\r
+//\r
+function add_zeroes($num, $places) { //Zarovna cislo na $places mist pridanim nul na zacatek\r
+ $str = "";\r
+ for($i=0;$i<$places;$i++) {\r
+ $str = $str."0";\r
+ }\r
+ //$num = base_convert($num, 10, $base); //BASE CONVERT -> !!! NOT WORKS YET !!! <-\r
+ $str=$str.$num;\r
+ $str = substr($str, strlen($str)-$places);\r
+ return $str;\r
+}\r
+\r
+///CODE///////////////////////////////////////////\r
+//Test\r
+//die(add_zeroes(23, 5));\r
+//////////////////////////////////////////////////\r
+$try = $tryes;\r
+$next = true;\r
+while($next) { //MAIN LOOP\r
+ $next = false;\r
+ \r
+ $rada = ""; //Vytvorime prazdnou radu\r
+ for($i=$start;$i<=$stop;$i++) { //Pridame vsechna n-cisli\r
+ $istr = add_zeroes($i, $places);\r
+ rada_add("rada", $istr);\r
+ }\r
+\r
+ rada_unique("rada");\r
+ \r
+ $notfound = 0;\r
+ for($i=$start;$i<=$stop;$i++) {\r
+ $istr = add_zeroes($i, $places);\r
+ if(!eregi($istr, $rada)) {\r
+ $notfound++;\r
+ //echo("Not found: $i\n");\r
+ $next = true;\r
+ }\r
+ }\r
+ \r
+ echo("Total not found: $notfound\n"); //Debug\r
+ \r
+ if($try > 0) {\r
+ if($notfound <= $minnotfound || !isset($minnotfound)) {\r
+ echo("-minnf: $notfound\n"); //Debug\r
+ $minnotfound = $notfound;\r
+ $try = $tryes;\r
+ } else {\r
+ $try--;\r
+ }\r
+ } else {\r
+ if($notfound <= $minnotfound || $notfound == 0) $next = false;\r
+ }\r
+ \r
+} //MAIN LOOP\r
+\r
+for($i=$start;$i<=$stop;$i++) { //Pridame vsechna zbyla n-cisli\r
+ $istr = add_zeroes($i, $places);\r
+ rada_add("rada", $istr);\r
+ }\r
+\r
+/////////OUTPUT///////////////////////////////////\r
+echo("\n");\r
+echo("Length: ".strlen($rada)." chars\n");\r
+echo("Total not found: $notfound\n");\r
+echo($rada);\r
+echo("\n\n");\r