网上搜了一下找缩水算法的介绍,发觉大家都藏藏掖掖的。
以下是网上搜到的一个通过加工以后的源码。
来处上一篇的双色球小工具中的源码(部分)
package { import flash.display.MovieClip; import flash.events.MouseEvent; import flash.events.Event; import flash.text.TextFormat; public class ZipMovieClip extends MovieClip { // Constants: // Public Properties: // Private Properties: private var yxh:String=","; private var hz_arr:Array=[]; private var jo_arr:Array=[]; private var ds_arr:Array=[]; private var jg_count:int=0; private var xy_count:int=0; public function ZipMovieClip() { //界面交互操作处理开始 close_btn.addEventListener(MouseEvent.CLICK,closeHandler); btn_1.addEventListener(MouseEvent.CLICK,btnHandler); btn_2.addEventListener(MouseEvent.CLICK,btnHandler); btn_3.addEventListener(MouseEvent.CLICK,btnHandler); btn_4.addEventListener(MouseEvent.CLICK,btnHandler); btn_5.addEventListener(MouseEvent.CLICK,btnHandler); btn_6.addEventListener(MouseEvent.CLICK,btnHandler); btn_7.addEventListener(MouseEvent.CLICK,btnHandler); btn_8.addEventListener(MouseEvent.CLICK,btnHandler); btn_9.addEventListener(MouseEvent.CLICK,btnHandler); btn_10.addEventListener(MouseEvent.CLICK,btnHandler); btn_11.addEventListener(MouseEvent.CLICK,btnHandler); btn_12.addEventListener(MouseEvent.CLICK,btnHandler); btn_13.addEventListener(MouseEvent.CLICK,btnHandler); btn_14.addEventListener(MouseEvent.CLICK,btnHandler); btn_15.addEventListener(MouseEvent.CLICK,btnHandler); btn_16.addEventListener(MouseEvent.CLICK,btnHandler); btn_17.addEventListener(MouseEvent.CLICK,btnHandler); btn_18.addEventListener(MouseEvent.CLICK,btnHandler); btn_19.addEventListener(MouseEvent.CLICK,btnHandler); btn_20.addEventListener(MouseEvent.CLICK,btnHandler); btn_21.addEventListener(MouseEvent.CLICK,btnHandler); btn_22.addEventListener(MouseEvent.CLICK,btnHandler); btn_23.addEventListener(MouseEvent.CLICK,btnHandler); btn_24.addEventListener(MouseEvent.CLICK,btnHandler); btn_25.addEventListener(MouseEvent.CLICK,btnHandler); btn_26.addEventListener(MouseEvent.CLICK,btnHandler); btn_27.addEventListener(MouseEvent.CLICK,btnHandler); btn_28.addEventListener(MouseEvent.CLICK,btnHandler); btn_29.addEventListener(MouseEvent.CLICK,btnHandler); btn_30.addEventListener(MouseEvent.CLICK,btnHandler); btn_31.addEventListener(MouseEvent.CLICK,btnHandler); btn_32.addEventListener(MouseEvent.CLICK,btnHandler); btn_33.addEventListener(MouseEvent.CLICK,btnHandler); reset_btn.addEventListener(MouseEvent.CLICK,resetHandler); ctreate_btn.addEventListener(MouseEvent.CLICK,createHandler); //界面交互操作结束 var tfo:TextFormat = new TextFormat(); tfo.size=14; resultText.setStyle("defaultTextFormat", tfo); resultText.setStyle("textFormat", tfo); resultText.text=""; } //关闭事件处理 private function closeHandler(e:Event):void { var p=(e.target.parent) as MovieClip; p.parent.removeChild(p); } private function btnHandler(e:Event):void { var n:String=e.target.name; n=n.replace(/btn_/i,''); n=n.length<2?"0"+n:n; if (yxh.indexOf(","+n+",")>-1) { return; } yxh+=n+","; yxh_txt.text=yxh; } private function resetHandler(e:Event):void { yxh_txt.text=''; yxh=','; } //生成号码事件处理 private function createHandler(e:Event):void { jg_count=0; jo_arr.length=0; hz_arr.length=0; resultText.text=""; string2intArray(jiou_txt.text,jo_arr); string2intArray(hezhi_txt.text,hz_arr); string2intArray(dashu_txt.text,ds_arr); xy_count=parseInt(count_txt.text); if(jo_arr.length==1)jo_arr.push(6); if(hz_arr.length==1)hz_arr.push(500); if(ds_arr.length==1)ds_arr.push(6); var arr1:Array = yxh.split(","); var arr2:Array = []; for each (var __s:String in arr1){ if(/^\d+$/.test(__s)){ arr2.push(parseInt(__s)); } } arr1=null; createNumbers(arr2,printResult,6); //判断结果不否为空 if(resultText.text==""){ resultText.text="不中啊,你设置的条件太变态了,都选不出来数据了。请你修改选号条件重新自动生成号码吧。" } } //组合算法开始 // //用于生成组合号码 private function createNumbers(rang:Array,proceFn:Function,len:int=6,save:int=4):void { if (rang==null||proceFn==null) { return; } var temp_arr:Array=[]; var ret_arr:Array=[]; var l:int=rang.length; var i:int=0; var j:int=0; var count:int=0; var flag:Boolean=true; for(;i<l;i++){; temp_arr.push(i<len?1:0); } //第一组数据 while (flag) { flag=false; //生成一组数据 ret_arr.length=0; for (i=0; i<l; i++) { if (temp_arr[i]==1) { ret_arr.push(rang[i]); } } //处理本次生成的结果 if (!(proceFn(ret_arr,++count))) { break; } //生成完毕,需要变换 for (i=0; i<l-1; i++) { if (temp_arr[i]==1&&temp_arr[i+1]==0) { temp_arr[i]=0; temp_arr[i+1]=1; flag=true; //找到了 break; } } //移动游标 for(;i>0&&flag;i--){ if(temp_arr[i]==1){ for(j=0;j<i;j++){ if(temp_arr[j]==0){ //交换 temp_arr[j]=1; temp_arr[i]=0; break; } } } } } } //处理生成结果 private function printResult(p:Array,c:int):Boolean { //trace("第"+c+"组数据:"+p.join(",")); if(checkResult(p)){ jg_count++; var tmp:String=""; for each(var _tmp:int in p)tmp+=(_tmp>9?""+_tmp:"0"+_tmp)+" "; resultText.appendText(tmp+"\n"); } if (jg_count>=xy_count) { return false; } return true; } //转换成数组 private function string2intArray(src:String,arr:Array):void{ arr.length=0; if(src==null || src.length<1)return; var tmp:Array = src.split("-"); for each(var _tmp:String in tmp){ if(/^\d+$/.test(_tmp)) { arr.push(parseInt(_tmp)); } } } //验证生成的结果 private function checkResult(p:Array):Boolean{ if(jo_arr.length==0&&hz_arr.length==0 && ds_arr.length==0)return true; var flag:Boolean = false; var i:int = 0,j:int=0,d:int=0,t:int=0; for each ( i in p){ if((i%2)!=0)j++; if(i>16)d++; t+=i; } if(jo_arr.length>0){ //验证奇偶数 if(jo_arr.length==1) flag = (j>=jo_arr[0]); else (jo_arr.length>1) flag = (j>=jo_arr[0]&& j<=jo_arr[1]); }else flag=true; if(flag && hz_arr.length>0){ //验证和值 if(hz_arr.length==1) flag = (t>=hz_arr[0]); else (hz_arr.length>1) flag = (t>=hz_arr[0]&& t<=hz_arr[1]); } if(flag && ds_arr.length>0){ //验证大数 if(ds_arr.length==1) flag = (d>=ds_arr[0]); else (ds_arr.length>1) flag = (d>=ds_arr[0]&& d<=ds_arr[1]); } return flag; } } }