找回密码
 加入
搜索
查看: 278|回复: 3

[效率算法] 生成由4个数字,能组成的所有数字组合。

[复制链接]
发表于 2025-12-29 04:02:09 | 显示全部楼层 |阅读模式
本帖最后由 5735988 于 2025-12-29 04:44 编辑

#include <Array.au3>

Dim $aArray[5] = [1,3,2,6,8]
$aNewArray = _ArrayCombinations($aArray, 3,',')
_arraydisplay($aNewArray, "Array")
我想生成由这5个数字,能组成的10组数字。  
其中有2个数字一样的,不要。
比如 332     266    366   133  这样的不要,其他的保留。



主要是想生成 10套不一样的,三位数字
上面五个数字,随机生成 10套组合结果:
126   268    168  326   162  621  623   236    862   182  



===========================看了帮助一个小时,下面是自己写的,还是不对


Local $Y, $rand[5] = [5, 3, 2, 9, 6]
Local $_rStr = ""
$num = 3
For $j = 1 To $num
        Local $_tStr = $rand[Random(1, UBound($rand))]
        If StringInStr($_rStr, $_tStr) Then
                $j -= 1
                ContinueLoop
        EndIf
        $_rStr&= $_tStr&","
Next
MsgBox(0, 0, $_rStr)
有点接近了,还没好


 楼主| 发表于 2025-12-29 04:43:15 | 显示全部楼层

Local $Y, $rand[5] = [5, 3, 2, 9, 6]
Local $_rStr = ""
$num = 3
For $j = 1 To $num
        Local $_tStr = $rand[Random(1, UBound($rand))]
        If StringInStr($_rStr, $_tStr) Then
                $j -= 1
                ContinueLoop
        EndIf
        $_rStr&= $_tStr&","
Next
MsgBox(0, 0, $_rStr)


好像答案又接近了一点点。。。
发表于 2025-12-29 13:17:13 | 显示全部楼层
之前有个类似的帖子可以参考一下:

讨论一个题目的思路
https://www.autoitx.com/thread-73848-1-1.html
发表于 2026-3-1 07:01:25 | 显示全部楼层
#include <Array.au3>
Global $out[10]
Global $aArray[5] = [1, 3, 2, 6, 8]
Global $a, $b, $c, $d, $e = 0
Do
        Do
                $a = Random(0, 4, 1)
                $b = Random(0, 4, 1)
                $c = Random(0, 4, 1)
        Until ($a <> $b and $a <> $c and $b <> $c)
        $d = Int($aArray[$a] & $aArray[$b] & $aArray[$c])
        Local $iIndex = _ArraySearch($out, $d)
        If $iIndex = -1 Then
                $out[$e] = $d
                $e += 1
        EndIf
Until $e = UBound($out)
_ArrayDisplay($out)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2026-3-15 22:50 , Processed in 0.067425 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表