Skip to content

Commit 5a116ac

Browse files
authored
Merge pull request #13 from zhangxuanru/master
add ColorBricks how to write
2 parents f81f5a2 + 8df4b8c commit 5a116ac

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

package/Other/ColorBricks.php

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,71 @@ function ColorBricks($inputting)
6868
var_dump($group);
6969
}
7070

71-
echo ColorBricks("AABB");
71+
echo ColorBricks("AABB");
72+
73+
74+
#########################################
75+
76+
77+
78+
function ColorBricks2($str)
79+
{
80+
$count = strlen($str);
81+
$data = array();
82+
for($i = 0; $i < $count; $i++){
83+
$data[] = $str[$i];
84+
}
85+
$a = pre2($data);
86+
}
87+
88+
/*
89+
思路分析:
90+
91+
* 例如: s = "ABAB",那么小易有六种排列的结果:
92+
* "AABB","ABAB","ABBA","BAAB", "BBAA" "BABA",
93+
1-2 0 2-3 0-1 0-3 1-2
94+
"ABAB", 0
95+
"BAAB", 0-1
96+
"AABB", 0-2
97+
"BABA" 0-3
98+
"ABBA", 1-2
99+
"BBAA" 1-3
100+
101+
*/
102+
103+
function pre2($data)
104+
{
105+
$c = count($data);
106+
$new = array();
107+
$max = floor($c/2);
108+
for($i = 0; $i < $max;$i++){
109+
for($j = 1; $j < $c;$j++){
110+
$temp = $data[$j];
111+
$data[$j] = $data[0];
112+
$data[0] = $temp;
113+
$new[] = implode("",$data);
114+
echo '0##'.$j.'<br/>';
115+
}
116+
}
117+
$nMax = count($new);
118+
$successNumber = 0;
119+
for($i = 0 ; $i < $max;$i++){
120+
$success = false;
121+
for($j = 0; $j < $nMax;$j++){
122+
$str = $new[$j];
123+
if($str[$i] == $str[0]){
124+
$success = true;
125+
}
126+
}
127+
if($success)$successNumber++;
128+
}
129+
echo '<pre>';
130+
echo "小易可以有{$successNumber}种方式";
131+
echo "<br/><br/><br/><br/>";
132+
print_r($new);
133+
exit;
134+
}
135+
$str = "ABAB";
136+
ColorBricks2($str);
137+
138+

0 commit comments

Comments
 (0)