<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[静怡家园]]></title> 
<link>http://www.zhanghaijun.com/index.php</link> 
<description><![CDATA[书山有路勤为径，学海无涯苦作舟！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[静怡家园]]></copyright>
<item>
<link>http://www.zhanghaijun.com/post//</link>
<title><![CDATA[用php计算24点游戏]]></title> 
<author>碟舞飞扬 &lt;webmaster@zhanghaijun.com&gt;</author>
<category><![CDATA[Web开发]]></category>
<pubDate>Sat, 03 Feb 2007 19:09:24 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//</guid> 
<description>
<![CDATA[ 
	&lt;?php<br/>/***********************<br/>* 作者:大龄青年(QQ:303015292)<br/>* 主页:http://blog.csdn.net/hahawen<br/>* 功能:用php计算24点游戏 <br/>************************/<br/>set_time_limit(0);<br/>$values = array(1, 5, 5, 5);<br/>$result = 24;<br/>$list = array();<br/><br/>echo &quot;&lt;pre&gt;&quot;;<br/>makeValue($values);<br/>print_r($list);<br/>function makeValue($values, $set=array())<br/>{<br/> $words = array(&quot;+&quot;, &quot;-&quot;, &quot;*&quot;, &quot;/&quot;);<br/> if(sizeof($values)==1)<br/> {<br/>&nbsp;&nbsp;$set[] = array_shift($values);<br/>&nbsp;&nbsp;return makeSpecial($set);<br/> }<br/> foreach($values as $key=&gt;$value)<br/> {<br/>&nbsp;&nbsp;$tmpValues = $values;<br/>&nbsp;&nbsp;unset($tmpValues[$key]);<br/>&nbsp;&nbsp;foreach($words as $word)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp; makeValue($tmpValues, array_merge($set, array($value, $word)));<br/>&nbsp;&nbsp;}<br/> }<br/>} <br/><br/>function makeSpecial($set)<br/>{<br/> $size = sizeof($set);<br/> if($size&lt;=3 &#124;&#124; !in_array(&quot;/&quot;, $set) &amp;&amp; !in_array(&quot;*&quot;, $set))<br/> {<br/>&nbsp;&nbsp;return makeResult($set);<br/> }<br/> for($len=3; $len&lt;$size-1; $len+=2)<br/> {<br/>&nbsp;&nbsp;for($start=0; $start&lt;$size-1; $start+=2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp; if(!($set[$start-1]==&quot;*&quot; &#124;&#124; $set[$start-1]==&quot;/&quot; &#124;&#124; $set[$start+$len]==&quot;*&quot; &#124;&#124; $set[$start+$len]==&quot;/&quot;))<br/>&nbsp;&nbsp; continue;<br/>&nbsp;&nbsp; $subSet = array_slice($set, $start, $len);<br/>&nbsp;&nbsp; if(!in_array(&quot;+&quot;, $subSet) &amp;&amp; !in_array(&quot;-&quot;, $subSet))<br/>&nbsp;&nbsp; continue;<br/>&nbsp;&nbsp; $tmpSet = $set;<br/>&nbsp;&nbsp; array_splice($tmpSet, $start, $len-1);<br/>&nbsp;&nbsp; $tmpSet[$start] = &quot;(&quot;.implode(&quot;&quot;, $subSet).&quot;)&quot;;<br/>&nbsp;&nbsp; makeSpecial($tmpSet); <br/>&nbsp;&nbsp;}<br/> }<br/>} <br/><br/>function makeResult($set)<br/>{<br/> global $result, $list;<br/> $str = implode(&quot;&quot;, $set);<br/> @eval(&quot;$num=$str;&quot;);<br/> if($num==$result &amp;&amp; !in_array($str, $list))<br/> $list[] = $str;<br/>} <br/><br/>?&gt;
]]>
</description>
</item><item>
<link>http://www.zhanghaijun.com/post//#blogcomment</link>
<title><![CDATA[[评论] 用php计算24点游戏]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>