let targetLen = [4,6,6,4]
const BASE_URL = 'https://www.mxnzp.com/api/lottery/common/history?'
//目前提供七种彩种, ssq:双色球,qlc:七乐彩,fc3d:福彩3D,cjdlt:超级大乐透,qxc:七星彩,pl3:排列3,pl5:排列(5)
const CODE = 'pl5'
//获取近期多少期开奖结果,MAX=50
const SIZE = 20
const APP_ID = 'mditkgelskgstp6v'
const APP_SECRET = 'MXFnOWFKc2NjdlRjamVHSGVaL1hlZz09'
let url = BASE_URL+'code='+CODE+ '&size='+SIZE +'&app_id='+APP_ID+'&app_secret='+APP_SECRET
let baseData = [0,1,2,3,4,5,6,7,8,9]
let result = Array.from({length:4},()=>[])
let openCode =[]
fetch(url).then(function(response) {
if(response.status === 200){
return response.json();
}else{
return {}
}
}).then(json=>{
json.data.forEach(item=>{
openCode.push(item.openCode.split(',').splice(0,4))
})
//第一种规律,前十期相加取余数为目标code
let targetCodes = Array.from({length:4},()=>0)
let nowIndex = 0
let nowCode = (9+nowIndex)%10
openCode.forEach((code,index) =>{
if(index>nowIndex-1)
code.forEach((item,idx)=>{
targetCodes[idx] += Number(item)
})
if(index>nowIndex && index%10===nowCode){
targetCodes.forEach((targetItem,targetIdx)=>{
if(result[targetIdx].indexOf(targetItem%10)==-1)
result[targetIdx].push(targetItem%10)
})
}
})
//第二种规律走单双,单下标+1双下标+2
let targetIndex = Array.from({length:4},()=>0)
openCode.forEach((code,index) =>{
if(index>nowIndex-1)
code.forEach((item,idx)=>{
if(item%2==0){
targetIndex[idx]+=2
}else{
targetIndex[idx]+=1
}
})
if(index>nowIndex && index%10==nowCode){
targetIndex.forEach((targetItem,targetIdx)=>{
if(result[targetIdx].indexOf(targetItem%10)==-1)
result[targetIdx].push(targetItem%10)
})
}
})
let target= result.map(i=>{
return i.length==0?'X': i.sort().join('')
}).join('-')
console.log('Code',target)
})
// for(let i=0;i<4;i++){
// for(let j=0;j<targetLen[i];j++){
// let idx = 0
// do{
// idx = Math.floor(Math.random()*10)
// }while(result[i].indexOf(baseData[idx])!==-1)
// result[i].push(baseData[idx])
// }
// }
console