|
@@ -0,0 +1,239 @@
|
|
|
+package com.skyversation.poiaddr.util;
|
|
|
+
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 多看书、多睡觉、少做白日梦
|
|
|
+ */
|
|
|
+public class DreamTest {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算双色球中奖金额
|
|
|
+ *
|
|
|
+ * @param yourNumbers 你的号码数组,前6个为红球(1-33,不重复),第7个为蓝球(1-16)
|
|
|
+ * @param winningNumbers 中奖号码数组,前6个为红球,第7个为蓝球
|
|
|
+ * @return 中奖金额(元),未中奖返回0,输入无效返回-1
|
|
|
+ */
|
|
|
+ public static double calculateBonus(int[] yourNumbers, int[] winningNumbers) {
|
|
|
+ // 验证输入数组长度
|
|
|
+ if (yourNumbers == null || winningNumbers == null ||
|
|
|
+ yourNumbers.length != 7 || winningNumbers.length != 7) {
|
|
|
+ return -1; // 输入无效
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分离红球和蓝球
|
|
|
+ int[] yourRed = new int[6];
|
|
|
+ int yourBlue = yourNumbers[6];
|
|
|
+ System.arraycopy(yourNumbers, 0, yourRed, 0, 6);
|
|
|
+
|
|
|
+ int[] winningRed = new int[6];
|
|
|
+ int winningBlue = winningNumbers[6];
|
|
|
+ System.arraycopy(winningNumbers, 0, winningRed, 0, 6);
|
|
|
+
|
|
|
+ // 验证号码范围
|
|
|
+ if (!isValidRedBalls(yourRed) || !isValidBlueBall(yourBlue) ||
|
|
|
+ !isValidRedBalls(winningRed) || !isValidBlueBall(winningBlue)) {
|
|
|
+ return -1; // 号码范围无效
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算红球匹配数
|
|
|
+ int redMatches = countRedMatches(yourRed, winningRed);
|
|
|
+ // 计算蓝球是否匹配
|
|
|
+ boolean blueMatched = (yourBlue == winningBlue);
|
|
|
+
|
|
|
+ // 获取实时奖池金额(实际应用中应从官方API获取)
|
|
|
+ double jackpot = getJackpotAmount();
|
|
|
+
|
|
|
+ // 根据中奖规则计算奖金
|
|
|
+ if (redMatches == 6 && blueMatched) {
|
|
|
+ // 一等奖:奖池30%,最高1000万
|
|
|
+ return Math.min(jackpot * 0.3, 10000000);
|
|
|
+ } else if (redMatches == 6 && !blueMatched) {
|
|
|
+ // 二等奖:奖池15%
|
|
|
+ return jackpot * 0.15;
|
|
|
+ } else if (redMatches == 5 && blueMatched) {
|
|
|
+ // 三等奖:3000元
|
|
|
+ return 3000;
|
|
|
+ } else if ((redMatches == 5 && !blueMatched) || (redMatches == 4 && blueMatched)) {
|
|
|
+ // 四等奖:200元
|
|
|
+ return 200;
|
|
|
+ } else if ((redMatches == 4 && !blueMatched) || (redMatches == 3 && blueMatched)) {
|
|
|
+ // 五等奖:10元
|
|
|
+ return 10;
|
|
|
+ } else if ((redMatches == 2 && blueMatched) ||
|
|
|
+ (redMatches == 1 && blueMatched) ||
|
|
|
+ (redMatches == 0 && blueMatched)) {
|
|
|
+ // 六等奖:5元
|
|
|
+ return 5;
|
|
|
+ } else {
|
|
|
+ // 未中奖
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证红球是否有效(1-33,不重复)
|
|
|
+ */
|
|
|
+ private static boolean isValidRedBalls(int[] redBalls) {
|
|
|
+ Set<Integer> uniqueCheck = new HashSet<>();
|
|
|
+ for (int ball : redBalls) {
|
|
|
+ if (ball < 1 || ball > 33 || !uniqueCheck.add(ball)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证蓝球是否有效(1-16)
|
|
|
+ */
|
|
|
+ private static boolean isValidBlueBall(int blueBall) {
|
|
|
+ return blueBall >= 1 && blueBall <= 16;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算红球匹配数量
|
|
|
+ */
|
|
|
+ private static int countRedMatches(int[] yourRed, int[] winningRed) {
|
|
|
+ Set<Integer> winningSet = new HashSet<>();
|
|
|
+ for (int ball : winningRed) {
|
|
|
+ winningSet.add(ball);
|
|
|
+ }
|
|
|
+
|
|
|
+ int count = 0;
|
|
|
+ for (int ball : yourRed) {
|
|
|
+ if (winningSet.contains(ball)) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static double getJackpotAmount() {
|
|
|
+ // 此处仅为示例,返回一个模拟值
|
|
|
+ return 2427919422.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int[] generateRandomRedBalls(List<Integer> number, Integer number2) {
|
|
|
+ // 创建1-33的数字列表
|
|
|
+ List<Integer> numbers = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= 33; i++) {
|
|
|
+ if (number != null && number.size() > 0) {
|
|
|
+ if (!number.contains(i)) {
|
|
|
+ numbers.add(i);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ numbers.add(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Integer> numbers2 = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= 16; i++) {
|
|
|
+ if (number2 == null || i != number2) {
|
|
|
+ numbers2.add(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 打乱列表顺序
|
|
|
+ Collections.shuffle(numbers, new Random());
|
|
|
+ Collections.shuffle(numbers2, new Random());
|
|
|
+ // 取前6个数字
|
|
|
+ int[] result = new int[6];
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ result[i] = numbers.get(i);
|
|
|
+ }
|
|
|
+ // 排序结果
|
|
|
+ Arrays.sort(result);
|
|
|
+ int[] result2 = new int[7];
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ result2[i] = result[i];
|
|
|
+ }
|
|
|
+ result2[6] = numbers2.get(0);
|
|
|
+ return result2;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static double test(int hfSum, int bs) {
|
|
|
+ int sumMn = hfSum / 2 / bs;
|
|
|
+ double re = 0;
|
|
|
+ List<Integer> upList = new ArrayList<>();
|
|
|
+ Integer endNumber = null;
|
|
|
+ String upNumbers = "";
|
|
|
+ String[] upStringList = upNumbers.split(", ");
|
|
|
+ if (upStringList.length > 0) {
|
|
|
+ for (int i = 0; i < upStringList.length; i++) {
|
|
|
+ if (i == upStringList.length - 1) {
|
|
|
+ if (StringUtils.hasText(upStringList[i])) {
|
|
|
+ endNumber = Integer.valueOf(upStringList[i]);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (StringUtils.hasText(upStringList[i])) {
|
|
|
+ upList.add(Integer.valueOf(upStringList[i]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int[] winningNumbers = generateRandomRedBalls(null, null);
|
|
|
+ List<int[]> myNumbersList = new ArrayList<>();
|
|
|
+ while (sumMn > 0) {
|
|
|
+ int[] myNumbers = generateRandomRedBalls(upList, endNumber);
|
|
|
+ if (delLpNumbers(myNumbers) && !myNumbersList.contains(myNumbers)) {
|
|
|
+ myNumbersList.add(myNumbers);
|
|
|
+ sumMn--;
|
|
|
+ double bonus = calculateBonus(myNumbers, winningNumbers);
|
|
|
+ if (bonus != -1 && bonus != 0) {
|
|
|
+ re += bs * bonus;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return re;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean delLpNumbers(int[] numbers) {
|
|
|
+ if (numbers[5] - numbers[0] < 11) {
|
|
|
+ System.out.println(Arrays.toString(numbers));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int lh = 0;
|
|
|
+ int cz = 1;
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ if (numbers[i + 1] - numbers[i] == cz) {
|
|
|
+ lh++;
|
|
|
+ if (lh >= 4) {
|
|
|
+ System.out.println(Arrays.toString(numbers));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ lh = 0;
|
|
|
+ cz = numbers[i + 1] - numbers[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 示例用法1849397248分之一
|
|
|
+ public static void main(String[] args) {
|
|
|
+// 测试次数(一周两次的话,需要testCount/2/4/12,普通人一生也就最多10000次)一年100次左右
|
|
|
+ int testCount = 100;
|
|
|
+// 人数
|
|
|
+ int pNum = 1000;
|
|
|
+// 每人金额
|
|
|
+ int cSum = 100;
|
|
|
+// 单次总金额
|
|
|
+ int allSum = cSum * pNum;
|
|
|
+// 倍率
|
|
|
+ int bs = 1;
|
|
|
+// 总中奖
|
|
|
+ double res = 0.0;
|
|
|
+ for (int i = 0; i < testCount; i++) {
|
|
|
+ res += test(allSum, bs);
|
|
|
+ }
|
|
|
+ System.out.println("----------------------年总结----------------------");
|
|
|
+ System.out.println(pNum + "人参与!");
|
|
|
+ System.out.println("每次每人投入" + cSum + "元!");
|
|
|
+ System.out.println("每次" + bs + "倍," + (allSum / 2 / bs) + "注,单次金额:" + allSum);
|
|
|
+ System.out.println("一年买了" + testCount + "次,总金额:" + allSum * testCount + ",中了:" + res + ",回本率:" + (res / allSum / testCount));
|
|
|
+ double edOrHd = (res / pNum) - (testCount * cSum);
|
|
|
+ System.out.println("每人总投注:" + testCount * cSum + ",每人" + (edOrHd > 0 ? "赚了" : "亏了") + edOrHd);
|
|
|
+ }
|
|
|
+}
|