生成 49/6 彩票可能的数字序列

发布于 2024-11-28 18:03:05 字数 90 浏览 5 评论 0原文

我想生成 49 6 彩票的所有可能序列

因此我需要从 1 到 49 组中抽出的 6 个球的编号序列。

我可以获得生成这些序列的逻辑吗?

I want to generate all possible sequence for 49 6 lottery

So I need number sequence for 6 ball drawn from group of 1 to 49.

Can I get logic to generate these sequences?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

亣腦蒛氧 2024-12-05 18:03:05

这是一篇写得很好的文章,涵盖了组合和排列的各种场景。文章末尾还有一个很好的参考文献列表。

http://www.codingthewheel.com/archives/exhaustively -代码中枚举组合和排列

Here is a well written article that covers the various scenarios of combinations and permutations. It also has a nice list of references at the end of the article.

http://www.codingthewheel.com/archives/exhaustively-enumerating-combinations-and-permutations-in-code

不交电费瞎发啥光 2024-12-05 18:03:05
<?php

$totalOutcomesEnumerated = 0;

for ($ball1 = 1; $ball1 < 45; $ball1++) {
  for ($ball2 = $ball1 + 1; $ball2 < 46; $ball2++) {
    for ($ball3 = $ball2 + 1; $ball3 < 47; $ball3++) {
      for ($ball4 = $ball3 + 1; $ball4 < 48; $ball4++) {
        for ($ball5 = $ball4 + 1; $ball5 < 49; $ball5++) {
          for ($ball6 = $ball5 + 1; $ball6 < 50; $ball6++) {
            // Each iteration of this loop visits a single outcome
            $totalOutcomesEnumerated++;
            echo $ball1 . ',' . $ball2 . ',' . $ball3 . ',' . $ball4 . ',' . $ball5 . ',' . $ball6 . PHP_EOL;
          }
        }
      }
    }
  }
}

echo 'Total outcomes : ' . $totalOutcomesEnumerated . PHP_EOL ; // 13983816
<?php

$totalOutcomesEnumerated = 0;

for ($ball1 = 1; $ball1 < 45; $ball1++) {
  for ($ball2 = $ball1 + 1; $ball2 < 46; $ball2++) {
    for ($ball3 = $ball2 + 1; $ball3 < 47; $ball3++) {
      for ($ball4 = $ball3 + 1; $ball4 < 48; $ball4++) {
        for ($ball5 = $ball4 + 1; $ball5 < 49; $ball5++) {
          for ($ball6 = $ball5 + 1; $ball6 < 50; $ball6++) {
            // Each iteration of this loop visits a single outcome
            $totalOutcomesEnumerated++;
            echo $ball1 . ',' . $ball2 . ',' . $ball3 . ',' . $ball4 . ',' . $ball5 . ',' . $ball6 . PHP_EOL;
          }
        }
      }
    }
  }
}

echo 'Total outcomes : ' . $totalOutcomesEnumerated . PHP_EOL ; // 13983816
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文