-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfac.php
More file actions
62 lines (55 loc) · 1.32 KB
/
fac.php
File metadata and controls
62 lines (55 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
* Author Samark Chaisanguan
* For calculate all summary of event like simple space
* ex. input abc output:- (a,b,c) , (a,c,b) (b,a,c) ,(b,c,a) (c,a,b), (c,b,a)
* Ran only command line
*/
$arg = $argv[1];
$get = str_split($arg,1);
// debug($get);
$cnt = count($get);
if($cnt ==1) echo $get[0];//debug($get,false,true);
for($i=0;$i<$cnt ;$i++) {
// $segment = $get[$i];
// unset($get[$i]);
// $get[$cnt-1] = $segment;
if($i== 0) {
// echo 'x';
// concate_string($get[$i],$get);
}else{
$m=0;
while($m <=$cnt-1 ) {
$shift = array_shift($get);
$push = array_push($get,$shift);
concate_string($get[$i],$get);
$m ++;
}
// debug($get);
}
}
function concate_string($start,$array=array()) {
if(($key = array_search($start, $array)) !== false) {
unset($array[$key]);
$j= '';
$k=1;
$cnt = count($array);
$fac = array();
foreach($array as $key => $val) {
if($k==1) {
$j .= $start.",".$val;
}else{
$j .= ",".$val;
}
++$k;
// echo "K:".$k."\r\n";
}
echo trim($j)."\r\n";
}
}
function debug($data=array(),$v=false,$e=false) {
echo "<pre>"; print_r($data); echo "</pre>";
if($v== true) var_dump($data);
if($e==true) exit('woow');
}
?>