最近APP预测情况:蓝球最近出的逻辑明显跟前一阵的逻辑有较大变化,导致预测模型不大匹配了,还需要进一步观察规律,重新调整模型,红球最高预测仍然只有5个号,不过最近发现了一个新规律,大大的增加了筛选率。
前一阵在研究TensorFlow,没时间更新,最近打算抽时间把之前那个彩票APP的实现步骤梳理一下,方便感兴趣的朋友可以试着自己也可以搞一个。今天主要说说数据准备相关的实现。
首先,要分析彩票,当然得把所有的彩票组合给准备好,这个挺简单,主要就是高中的排列组合问题。我自己的实现方式就不说了,网上搜一下一大把,最近没事就调戏ChatGPT,看看它给出的算法吧(ChatGPT真的挺牛逼的,但是需要科学上网,一般人还是不容易用上,所有后面打算在APP里面把这个功能也加上)。
import java.util.ArrayList;
import java.util.List;
public class AllCombinations {
public static void main(String[] args) {
int[] numbers = new int[33];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = i + 1;
}
List<int[]> combinations = selectSixNumbers(numbers);
for (int[] combination : combinations) {
System.out.println(Arrays.toString(combination));
}
}
public static List<int[]> selectSixNumbers(int[] numbers) {
List<int[]> combinations = new ArrayList<>();
selectSixNumbersHelper(numbers, 0, 6, new int[6], combinations);
return combinations;
}
public static void selectSixNumbersHelper(int[] numbers, int start, int k, int[] temp, List<int[]> combinations) {
if (k == 0) {
combinations.add(temp.clone());
return;
}
for (int i = start; i <= numbers.length - k; i++) {
temp[temp.length - k] = numbers[i];
selectSixNumbersHelper(numbers, i + 1, k - 1, temp, combinations);
}
}
}
其次,要从网上抓取历史开奖数据,用作分析,这个需要找个稳定的网站,用浏览器控制台分析一下网络响应,找到包含开奖信息的请求,然后分析一下响应结构,用正则匹配一下即可。
URL url = new URL("https://zst.yingti666.com/ssq/sanfq/?eIssue=&endIssue="
+ nowIssue
+ "&maxsize=1000&openDate=&sIssue=&sortTag=up&startIssue="
+ startIssue + "&statisticsTag=1");
InputStream instr = url.openStream();
String s;
reds = new ArrayList<>();
BufferedReader in = new BufferedReader(new InputStreamReader(instr,
"utf-8"));
int index = 0;
String[] lottery = new String[6];
boolean isNowIssue = false;
int red = 1;
while ((s = in.readLine()) != null) {
if (s.indexOf("<td class=\"c_fbf5e3 bd_rt_a\">" + nowIssue
+ "</td>") != -1) {
isNowIssue = true;
} else if (s.indexOf("chartBall01") != -1) {
if (isNowIssue) {
red++;
}
Pattern p = Pattern.compile(">\\d{1,2}<");
Matcher m = p.matcher(s);
if (m.find()) {
Pattern p2 = Pattern.compile("\\d{1,2}");
Matcher m2 = p2.matcher(m.group());
if (m2.find()) {
lottery[index] = m2.group();
index++;
if (index == 6) {
reds.add(lottery);
index = 0;
lottery = new String[6];
}
}
}
} else if (s.indexOf("chartBall02") != -1) {
isNowIssue = false;
Pattern p = Pattern.compile(">\\d{1,2}<");
Matcher m = p.matcher(s);
if (m.find()) {
Pattern p2 = Pattern.compile("\\d{1,2}");
Matcher m2 = p2.matcher(m.group());
if (m2.find()) {
blue.add(m2.group());
}
}
} else if (isNowIssue && s.indexOf("yl01") != -1 && red <= 33) {
Pattern p = Pattern.compile(">\\d{1,2}<");
Matcher m = p.matcher(s);
if (m.find()) {
Pattern p2 = Pattern.compile("\\d{1,2}");
Matcher m2 = p2.matcher(m.group());
if (m2.find()) {
int num = Integer.parseInt(m2.group());
if (num >= 5) {
xm.add(red);
}
}
}
red++;
}
}
有了以上两个数据就可以准备进行分析删选了,下一篇文章讲讲常用的筛选规则。