V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
tcpdump
V2EX  ›  JavaScript

Javascript 组合算法的问题

  •  
  •   tcpdump · 2017-10-20 23:10:41 +08:00 · 2968 次点击
    这是一个创建于 2589 天前的主题,其中的信息可能已经有所发展或是发生改变。

    组合长度:4 (变量) X 在 组合里的个数:2 (变量) 数字在组合里的个数:4 - 2 (变量)

    生成 X 和数字的所有排列组合, 例如如下:

    X0X0
    0X0X
    X1X2
    
    
    5 条回复    2017-10-22 22:33:45 +08:00
    Hypn0s
        1
    Hypn0s  
       2017-10-21 23:51:38 +08:00
    大概想了想,采用 11 进制,11 用 X 表示,遍历所有位数在组合长度以下的数字( 11 进制),找出满足规则的数字就 OK 了。
    Hypn0s
        2
    Hypn0s  
       2017-10-22 00:07:28 +08:00
    @Hypn0s 说错了,是 10 用 X 表示
    qwertyegg
        3
    qwertyegg  
       2017-10-22 08:46:16 +08:00
    外层循环(C(4,2)次,4 个位置里面,有 2 个为 X)
    内层循环(10^2 次,(0,0)...(0,9), (1,0)...(1,9)...(9,0)....(9,9)) 填到两个数字位上

    总共 C(4,2)*100 步


    ps.为什么数字在组合里的个数是 2-4 ?组合长度为 4,X 有 2 个,难道不是一定 2 个数字?
    seognilV2
        4
    seognilV2  
       2017-10-22 09:22:38 +08:00 via Android
    @qwertyegg X 的个数是变量 n 数字个数 4-n 应该是这意思
    tcpdump
        5
    tcpdump  
    OP
       2017-10-22 22:33:45 +08:00
    例如如下
    ```
    ["0XX0","0XX1","0XX2","0XX3","0XX4","0XX5","0XX6","0XX7","0XX8","0XX9","1XX0","1XX1","1XX2","1XX3","1XX4","1XX5","1XX6","1XX7","1XX8","1XX9","2XX0","2XX1","2XX2","2XX3","2XX4","2XX5","2XX6","2XX7","2XX8","2XX9","3XX0","3XX1","3XX2","3XX3","3XX4","3XX5","3XX6","3XX7","3XX8","3XX9","4XX0","4XX1","4XX2","4XX3","4XX4","4XX5","4XX6","4XX7","4XX8","4XX9","5XX0","5XX1","5XX2","5XX3","5XX4","5XX5","5XX6","5XX7","5XX8","5XX9","6XX0","6XX1","6XX2","6XX3","6XX4","6XX5","6XX6","6XX7","6XX8","6XX9","7XX0","7XX1","7XX2","7XX3","7XX4","7XX5","7XX6","7XX7","7XX8","7XX9","8XX0","8XX1","8XX2","8XX3","8XX4","8XX5","8XX6","8XX7","8XX8","8XX9","9XX0","9XX1","9XX2","9XX3","9XX4","9XX5","9XX6","9XX7","9XX8","9XX9","0X0X","0X1X","0X2X","0X3X","0X4X","0X5X","0X6X","0X7X","0X8X","0X9X","1X0X","1X1X","1X2X","1X3X","1X4X","1X5X","1X6X","1X7X","1X8X","1X9X","2X0X","2X1X","2X2X","2X3X","2X4X","2X5X","2X6X","2X7X","2X8X","2X9X","3X0X","3X1X","3X2X","3X3X","3X4X","3X5X","3X6X","3X7X","3X8X","3X9X","4X0X","4X1X","4X2X","4X3X","4X4X","4X5X","4X6X","4X7X","4X8X","4X9X","5X0X","5X1X","5X2X","5X3X","5X4X","5X5X","5X6X","5X7X","5X8X","5X9X","6X0X","6X1X","6X2X","6X3X","6X4X","6X5X","6X6X","6X7X","6X8X","6X9X","7X0X","7X1X","7X2X","7X3X","7X4X","7X5X","7X6X","7X7X","7X8X","7X9X","8X0X","8X1X","8X2X","8X3X","8X4X","8X5X","8X6X","8X7X","8X8X","8X9X","9X0X","9X1X","9X2X","9X3X","9X4X","9X5X","9X6X","9X7X","9X8X","9X9X","00XX","01XX","02XX","03XX","04XX","05XX","06XX","07XX","08XX","09XX","10XX","11XX","12XX","13XX","14XX","15XX","16XX","17XX","18XX","19XX","20XX","21XX","22XX","23XX","24XX","25XX","26XX","27XX","28XX","29XX","30XX","31XX","32XX","33XX","34XX","35XX","36XX","37XX","38XX","39XX","40XX","41XX","42XX","43XX","44XX","45XX","46XX","47XX","48XX","49XX","50XX","51XX","52XX","53XX","54XX","55XX","56XX","57XX","58XX","59XX","60XX","61XX","62XX","63XX","64XX","65XX","66XX","67XX","68XX","69XX","70XX","71XX","72XX","73XX","74XX","75XX","76XX","77XX","78XX","79XX","80XX","81XX","82XX","83XX","84XX","85XX","86XX","87XX","88XX","89XX","90XX","91XX","92XX","93XX","94XX","95XX","96XX","97XX","98XX","99XX"]
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1800 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 83ms · UTC 16:28 · PVG 00:28 · LAX 08:28 · JFK 11:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.