彩票实现一,数据准备

文章讲述了彩票APP预测模型遇到的问题,即蓝球逻辑变化导致模型不匹配,需要重新调整。作者分享了如何准备所有彩票组合的数据,并提供了Java代码示例。此外,还介绍了抓取历史开奖数据的方法,利用正则表达式解析网页获取信息,为后续的分析筛选做准备。
摘要由CSDN通过智能技术生成

最近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++;
            }
        }

有了以上两个数据就可以准备进行分析删选了,下一篇文章讲讲常用的筛选规则。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值